-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
68 lines (59 loc) · 1.64 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
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
if (process.env.NODE_ENV !== 'production') {
var showedNotFoundStyles = {};
}
var cssmem = function (styles) {
return function (elem) {
return function (mods, mix) {
if (process.env.NODE_ENV !== 'production') {
if (!styles) {
throw new Error('There is no styles');
}
if (!elem) {
throw new Error('There is no element name');
}
}
var classes = [elem];
if (mods) {
Object.getOwnPropertyNames(mods).forEach(function (modName) {
var modVal = mods[modName];
if (modVal === true) {
classes.push(elem + cssmem.config.elemDelimiter + modName);
} else if (modVal) {
classes.push(
elem +
cssmem.config.elemDelimiter +
modName +
cssmem.config.modDelimiter +
modVal
);
}
});
}
return classes
.map(function (className, inx) {
if (typeof styles[className] === 'string') {
return styles[className];
} else {
if (process.env.NODE_ENV !== 'production') {
if (
!(className in showedNotFoundStyles) &&
inx === classes.length - 1
) {
console.warn(className, 'property not found in styles');
showedNotFoundStyles[className] = true;
}
}
return '';
}
})
.filter(Boolean)
.concat(mix || [])
.join(' ');
};
};
};
cssmem.config = {
elemDelimiter: '_',
modDelimiter: '_',
};
module.exports = cssmem;