UNPKG

903 BJavaScriptView Raw
1/* @flow */
2
3import appendPxIfNeeded from './append-px-if-needed';
4import camelCasePropsToDashCase from './camel-case-props-to-dash-case';
5import mapObject from './map-object';
6import {getPrefixedStyle} from './prefixer';
7
8function createMarkupForStyles(style: Object): string {
9 return Object.keys(style)
10 .map(property => {
11 return property + ': ' + style[property] + ';';
12 })
13 .join('\n');
14}
15
16export default function cssRuleSetToString(
17 selector: string,
18 rules: Object,
19 userAgent: ?string
20): string {
21 if (!rules) {
22 return '';
23 }
24
25 const rulesWithPx = mapObject(rules, (value, key) =>
26 appendPxIfNeeded(key, value));
27 const prefixedRules = getPrefixedStyle(rulesWithPx, userAgent);
28 const cssPrefixedRules = camelCasePropsToDashCase(prefixedRules);
29 const serializedRules = createMarkupForStyles(cssPrefixedRules);
30 return selector + '{' + serializedRules + '}';
31}