-
Notifications
You must be signed in to change notification settings - Fork 798
Expand file tree
/
Copy pathutils.js
More file actions
82 lines (57 loc) · 1.62 KB
/
Copy pathutils.js
File metadata and controls
82 lines (57 loc) · 1.62 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const Color = require('color');
function getVariableValue(value) {
let varValue = '';
// Value is defined as color
if (typeof value.string === 'function') {
varValue = value.string();
}
// Value is defined as object, use SASS map
else if (typeof value === 'object') {
varValue = {};
Object.keys(value).map(function(key) {
varValue[key] = getVariableValue(value[key]);
});
return varValue;
}
// Values is defined as functions as well
else if (typeof value === 'function') {
// Execute function
varValue = value();
// Get value
varValue = getVariableValue(varValue);
}
// Value is defined as string
else {
varValue = value;
}
return varValue;
}
function getColors(colorsObj, excludeShades) {
let res = {};
Object.keys(colorsObj).map(function(key) {
let val = colorsObj[key];
let keyKebab = toKebabCase(key);
if (typeof val === 'string') {
res[keyKebab] = Color(val);
}
else if (typeof val === 'object') {
res[keyKebab] = Color(val[500]);
if (excludeShades) {
return;
}
Object.keys(val).map(function(shadeKey) {
let shadeKeyKebab = toKebabCase(shadeKey);
if (typeof val[shadeKey] === 'string') {
res[keyKebab + '-' + shadeKeyKebab] = Color(val[shadeKey]);
}
});
}
});
return res;
}
function toKebabCase(myStr) {
return !myStr ? null : myStr.replace(/([A-Z])/g, function (g) { return '-' + g[0].toLowerCase(); });
}
module.exports.toKebabCase = toKebabCase;
module.exports.getVariableValue = getVariableValue;
module.exports.getColors = getColors;