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