-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtransform.js
More file actions
62 lines (53 loc) · 1.03 KB
/
transform.js
File metadata and controls
62 lines (53 loc) · 1.03 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const rawGist = `
/***
laskdjf9as8djfalkdsfj
black background
*/
.body {
background: #000;
color: #fff;
font-family: sans-serif;
font-size: 16px;
}
some-other-component {
color: #fff;
font-family: sans-serif;
font-size: 16px;
background: #000;
}
/* some commant */
/* some multi line comment
cool
*/
/***
0a9s7doj21094ijdfsdf
white background
//www.google.com
*/
.body {
background: #fff;
color: #000;
font-family: sans-serif;
}
`
/*
output format should be:
{
id: string,
name: string,
urlMatch: string,
cssRaw: string,
options: {}
*/
const transform = (rawGist) => {
return rawGist
.split(/\/\*{3,}/)
.map((blocks) => blocks.trim())
.filter((blocks) => blocks.length > 0)
.map((blocks) => blocks.split('\n').map((block) => block.trim()))
.reduce((acc, block) => {
const [id, name, urlMatch, _, maybeNewLine, ...cssRaw] = block
return [...acc, { id, name, urlMatch, cssRaw: cssRaw.join('\n') }]
}, [])
}
console.log(transform(rawGist))