-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
40 lines (34 loc) · 1 KB
/
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
38
39
40
const { name } = require("./package.json");
const path = require("path");
module.exports = (job, settings, options, type) => {
return new Promise((resolve, reject) => {
options.layers.forEach(asset => {
const index = job.assets.findIndex(x => x.layerName == asset);
const color_string = getColorValue(job.assets[index].value)
const color = hexToRgb(color_string);
job.assets[index].value = color;
settings.logger.log(
`changed ${job.assets[index].layerName} value to ${color}`
);
});
resolve(job);
});
};
function hexToRgb(hex) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result
? [
(parseInt(result[1], 16) / 255).toFixed(2),
(parseInt(result[2], 16) / 255).toFixed(2),
(parseInt(result[3], 16) / 255).toFixed(2),
1
]
: null;
}
function getColorValue(colorStr){
if(!colorStr.startsWith('#')){
return colorStr
}
let editedClr = colorStr.slice(1)
return editedClr
}