-
Notifications
You must be signed in to change notification settings - Fork 500
/
Copy pathutil.js
63 lines (60 loc) · 1.43 KB
/
util.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
51
52
53
54
55
56
57
58
59
60
61
62
63
import colorString from 'color-string';
//returns a string "type" of input object
export function toType(obj) {
let type = getType(obj);
// some extra disambiguation for numbers
if (type === 'number') {
if (isNaN(obj)) {
type = 'nan';
} else if ((obj | 0) != obj) {
//bitwise OR produces integers
type = 'float';
} else {
type = 'integer';
}
}
if (type === 'string') {
const color = colorString.get(obj);
if (color) {
type = 'color';
}
}
return type;
}
//source: http://stackoverflow.com/questions/7390426/better-way-to-get-type-of-a-javascript-variable/7390612#7390612
function getType(obj) {
return {}.toString
.call(obj)
.match(/\s([a-zA-Z]+)/)[1]
.toLowerCase();
}
//validation for base-16 themes
export function isTheme(theme) {
const theme_keys = [
'base00',
'base01',
'base02',
'base03',
'base04',
'base05',
'base06',
'base07',
'base08',
'base09',
'base0A',
'base0B',
'base0C',
'base0D',
'base0E',
'base0F'
];
if (toType(theme) === 'object') {
for (var i = 0; i < theme_keys.length; i++) {
if (!(theme_keys[i] in theme)) {
return false;
}
}
return true;
}
return false;
}