-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
37 lines (31 loc) · 837 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const indentString = require('indent-string');
const renderObject = (input) => {
const selectors = Object.keys(input);
const render = (selector) => {
const style = input[selector];
const stylesArray = (Array.isArray(style) ?
style :
[style]
);
return `${selector} {
${
stylesArray.map((styleObject) => (
Object.keys(styleObject).map(
(property) => (typeof styleObject[property] === 'string' ?
` ${property}: ${styleObject[property]};\n` :
indentString(renderObject(styleObject), ' ')
)
).join('')
)).join('')
}}
`;
};
return selectors.map(render).join('\n');
};
module.exports = (jssStylesheet) => {
const stylesheets = (Array.isArray(jssStylesheet) ?
jssStylesheet :
[jssStylesheet]
);
return stylesheets.map(renderObject).join('\n');
};