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