UNPKG

1.7 kBJavaScriptView Raw
1'use strict';
2
3function eachTrue(base, callback, output) {
4 for (var key in base) {
5 if (base[key]) {
6 output = callback(key, output);
7 }
8 }
9
10 return output;
11}
12
13function normStrings(names, value, output) {
14 var length = names.length;
15
16 for (var i = 0; i < length; i++) {
17 if (names[i]) {
18 output[names[i]] = value;
19 }
20 }
21
22 return output;
23}
24
25function processItem(item, output) {
26 if (item && typeof item === 'object') {
27 if (Array.isArray(item)) {
28 normArray(item, output);
29 } else {
30 for (var key in item) {
31 if ({}.hasOwnProperty.call(item, key)) {
32 if (key) {
33 var value = item[key];
34
35 if (typeof value === 'function') {
36 value = value(eachTrue(output, function (key, result) {
37 result[key] = true;
38 return result;
39 }, {}), key.split(' '));
40 }
41
42 normStrings(key.split(' '), !!value, output);
43 }
44 }
45 }
46 }
47 } else if (typeof item === 'function') {
48 processItem(item(eachTrue(output, function (key, result) {
49 result[key] = true;
50 return result;
51 }, {})), output);
52 } else if (item != null) {
53 var names = "" + item;
54
55 if (names) {
56 normStrings(names.split(' '), true, output);
57 }
58 }
59}
60
61function normArray(array, output) {
62 var length = array.length;
63
64 for (var i = 0; i < length; i++) {
65 var item = array[i];
66 processItem(item, output);
67 }
68
69 return output;
70}
71
72function classes() {
73 return eachTrue(normArray(arguments, {}), function (name, result) {
74 return result ? result + " " + name : name;
75 }, '');
76}
77
78module.exports = classes;
79//# sourceMappingURL=classes.js.map