modules/Transformer.js
/**
* Creates a valid CSS string out of an object of styles
* @param {Object} styles - an object with CSS styles
* @param {string} unit - unit that gets applied to number values
*/
Creates a valid CSS string out of an object of styles
Creates a valid CSS string out of an object of styles
function toCSS(styles, options = { }) {
  const unit = options.unit || 'px'
  const ruleSeparator = options.ruleSeparator || ''
  const selectorSeparator = options.selectorSeparator || ''
  const indent = options.indent || ''
  return Object.keys(styles).reduce((rules, property) => {
    let value = styles[property]
    if (value instanceof Array) {
      value = value.join(';' + property + ':' + ruleSeparator + indent)
    }
    if (value instanceof Object) {
      rules += camelToDashCase(property) + '{' + selectorSeparator + toCSS(value, options) + selectorSeparator + '}' + selectorSeparator 
    } else {
      if (rules !== '') {
        rules += ';' + ruleSeparator
      }
      if (isNumber(property, value)) {
        value = value + unit
      }
      rules += indent + camelToDashCase(property) + ':' + value
    }
    return rules
  }, '')
}
function toCSS ( styles , options = { } ) { const unit = options . unit || 'px' const ruleSeparator = options . ruleSeparator || '' const selectorSeparator = options . selectorSeparator || '' const indent = options . indent || '' return Object . keys ( styles ) . reduce ( ( rules , property ) => { let value = styles [ property ] if ( value instanceof Array ) { value = value . join ( ';' + property + ':' + ruleSeparator + indent ) } if ( value instanceof Object ) { rules += camelToDashCase ( property ) + '{' + selectorSeparator + toCSS ( value , options ) + selectorSeparator + '}' + selectorSeparator } else { if ( rules !== '' ) { rules += ';' + ruleSeparator } if ( isNumber ( property , value ) ) { value = value + unit } rules += indent + camelToDashCase ( property ) + ':' + value } return rules } , '' ) }
Creates a valid CSS string out of an object of styles
Creates a valid CSS string out of an object of styles
// resolve multi values passed as an array // prerender nested style objects // eslint-disable-line // add an semicolon at the end of each rule (if not the last one) // automatically adds units to CSS properties that are not unitless // but are provided as a plain number