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
|
import * as fs from 'fs'
import Color from 'color'
import tmp from 'tmp'
export function createTempFile(content: string, options = {}): Promise<string> {
return new Promise((resolve, reject) => {
tmp.file(options, (err, path) => {
if (err) return reject(err)
fs.writeFile(path, content, 'utf8', err => {
if (err) return reject(err)
resolve(path)
})
})
})
}
export function getSvgColorFromValue(value: string): string {
if (typeof value !== 'string') return null
if (value === 'transparent') {
return 'none'
}
try {
let parsed = Color(value)
if (parsed.valpha === 0) return 'none'
return parsed.rgb().string()
} catch (err) {
return null
}
}
|