-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.js
50 lines (42 loc) · 1.34 KB
/
utilities.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
41
42
43
44
45
46
47
48
49
50
const fs = require('fs');
const env = require('./env.json')
var tinycolor = require("tinycolor2");
module.exports = {
fsDirectories: (path) => {
return fs.readdirSync(path).filter(function (file) {
return fs.statSync(path + '/' + file).isDirectory();
});
},
RemoveDuplicateItems: (path) => {
let result = []
for (let index = path.length - 1; index >= 0; index--) {
const item = path[index];
if (result.length === 0) {
result.push(item)
} else {
const lastItem = result[result.length - 1]
if (!lastItem.startsWith(item)) {
result.push(item)
}
}
}
return result.reverse()
},
RemoveExtraItems: (path) => {
return path.filter(item => !env.REMOVE_ITEMS.includes(item))
},
NormalizeBlackWhiteToken: (prop) => {
var color = tinycolor(prop.value);
if (tinycolor.equals(color, tinycolor("white")) ) {
return ['color', 'white']
} else if (tinycolor.equals(color, tinycolor("black")) ) {
return ['color', 'black']
} else {
return prop.path
}
},
NormalizeSemanticToPaletteToken: (path, name) => {
path[path.indexOf("color")] = name;
return path
},
}