Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.objToCss = void 0;

var _hyphenateStyleName = _interopRequireDefault(require("fbjs/lib/hyphenateStyleName"));

var _exotic = require("exotic");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// import isPlainObject from 'is-plain-object'
const objToCss = (obj, prevKey) => {
  const css = Object.keys(obj).filter(key => {
    const chunk = obj[key];
    return chunk !== undefined && chunk !== null && chunk !== false && chunk !== '';
  }).map(key => {
    if ((0, _exotic.isPlainObject)(obj[key])) {
      return objToCss(obj[key], key);
    }

    return `${(0, _hyphenateStyleName.default)(key)}: ${obj[key]};`;
  }).join(' ');
  return prevKey ? `${prevKey} {
  ${css}
}` : css;
};

exports.objToCss = objToCss;

const flatten = (chunks, executionContext) => chunks.reduce((ruleSet, chunk) => {
  /* Remove falsey values */
  if (chunk === undefined || chunk === null || chunk === false || chunk === '') {
    return ruleSet;
  }
  /* Flatten ruleSet */


  if (Array.isArray(chunk)) {
    return [...ruleSet, ...flatten(chunk, executionContext)];
  }
  /* Handle other components */


  if (chunk.hasOwnProperty('styledComponentId')) {
    // $FlowFixMe not sure how to make this pass
    return [...ruleSet, `.${chunk.styledComponentId}`];
  }
  /* Either execute or defer the function */
  // if (isFunction(chunk)) {


  if (typeof chunk === 'function') {
    return executionContext ? ruleSet.concat(...flatten([chunk(executionContext)], executionContext)) : ruleSet.concat(chunk);
  }
  /* Handle objects */


  return ruleSet.concat( // $FlowFixMe have to add %checks somehow to isPlainObject
  (0, _exotic.isPlainObject)(chunk) ? objToCss(chunk) : chunk.toString());
}, []);

var _default = flatten;
exports.default = _default;