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
38
39
40
41
42
43
44
45
|
import removeMeta from './removeMeta'
export function stringifyConfigValue(x: any): string {
if (typeof x === 'string') return x
if (typeof x === 'number') return x.toString()
if (Array.isArray(x)) {
return x
.filter((y) => typeof y === 'string')
.filter(Boolean)
.join(', ')
}
return null
}
export function stringifyCss(
obj: any,
{ indent = 0, selector }: { indent?: number; selector?: string } = {}
): string {
let indentStr = '\t'.repeat(indent)
if (obj.__decls === true) {
let before = ''
let after = ''
if (selector) {
before = `${indentStr}${selector} {\n`
after = `\n${indentStr}}`
indentStr += '\t'
}
return (
before +
Object.keys(removeMeta(obj)).reduce((acc, curr, i) => {
return `${acc}${i === 0 ? '' : '\n'}${indentStr}${curr}: ${obj[curr]};`
}, '') +
after
)
}
return Object.keys(removeMeta(obj)).reduce((acc, curr, i) => {
return `${acc}${i === 0 ? '' : '\n'}${indentStr}${curr} {\n${stringifyCss(
obj[curr],
{
indent: indent + 1,
selector,
}
)}\n${indentStr}}`
}, '')
}
|