-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcolors.js
45 lines (38 loc) · 1.03 KB
/
colors.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
const models = require('./mongo/models.mongo');
const db = require('./mongo/index');
var converter = require('css-color-converter');
const Dictionary = require('./lib/dictionary.model')
let main = async () => {
await db.dbIsReady()
let res = await models()['Color'].find().lean();
let a = [];
res.forEach(element => {
cName = element.name
a.push(safeColorConverter(cName))
});
Promise.all(a).then(res => {
process.exit(0);
});
}
const colorConverter = function (cName) {
return converter(cName.toLowerCase()).toHexString();
};
const safeColorConverter = function (cName) {
if (cName) {
let words = cName.split(/\/| |-/);
for (let i = 0; i < words.length; i++) {
try {
let cc = colorConverter(words[i]);
return Promise.resolve(cc);
} catch (e) {
body = {
name: words[i],
value: 'undefined',
type: 'color'
}
return new Dictionary().addDictionary(this.body)
}
}
}
};
main()