Repository URL to install this package:
|
Version:
1.2.9 ▾
|
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// @flow
const hyphenateStyleName_1 = __importDefault(require("fbjs/lib/hyphenateStyleName"));
const exotic_1 = require("exotic");
exports.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 (exotic_1.isObjPlain(obj[key]))
return exports.objToCss(obj[key], key);
return `${hyphenateStyleName_1.default(key)}: ${obj[key]};`;
})
.join(' ');
return prevKey
? `${prevKey} {
${css}
}`
: css;
};
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 (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
exotic_1.isObjPlain(chunk) ? exports.objToCss(chunk) : chunk.toString());
}, []);
exports.default = flatten;
//# sourceMappingURL=flatten.js.map