-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshadowJsonGenerator.js
More file actions
32 lines (25 loc) · 901 Bytes
/
shadowJsonGenerator.js
File metadata and controls
32 lines (25 loc) · 901 Bytes
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
const Color = require('color');
const convertShadowToJSON = (boxShadowCSS) =>
boxShadowCSS.split(", ").map(shadowLayer =>
shadowLayer.split(" ").reduce((shadowObject, shadowLayerItem, idx) => {
if (idx === 0) {
shadowObject["xValue"] = shadowLayerItem;
}
if (idx === 1) {
shadowObject["yValue"] = shadowLayerItem;
}
if (idx === 2) {
shadowObject["blur"] = shadowLayerItem;
}
if (idx === 3) {
shadowObject["spread"] = shadowLayerItem;
}
if (idx === 4) {
const shadowColor = Color(shadowLayerItem).object();
shadowObject["color"] = Color.rgb(shadowColor.r, shadowColor.g, shadowColor.b).hex();
shadowObject["alpha"] = shadowColor.alpha.toString();
}
return shadowObject;
}, {})
);
console.log(JSON.stringify(convertShadowToJSON("0 2px 0 0 rgba(22,17,28,0.1)")));