@odjs/classes
Version:
Classname management for @odjs/dom
86 lines (70 loc) • 2.15 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.classes = factory());
}(this, (function () { 'use strict';
function eachTrue(base, callback, output) {
for (var key in base) {
if (base[key]) {
output = callback(key, output);
}
}
return output;
}
function normStrings(names, value, output) {
var length = names.length;
for (var i = 0; i < length; i++) {
if (names[i]) {
output[names[i]] = value;
}
}
return output;
}
function processItem(item, output) {
if (item && typeof item === 'object') {
if (Array.isArray(item)) {
normArray(item, output);
} else {
for (var key in item) {
if ({}.hasOwnProperty.call(item, key)) {
if (key) {
var value = item[key];
if (typeof value === 'function') {
value = value(eachTrue(output, function (key, result) {
result[key] = true;
return result;
}, {}), key.split(' '));
}
normStrings(key.split(' '), !!value, output);
}
}
}
}
} else if (typeof item === 'function') {
processItem(item(eachTrue(output, function (key, result) {
result[key] = true;
return result;
}, {})), output);
} else if (item != null) {
var names = "" + item;
if (names) {
normStrings(names.split(' '), true, output);
}
}
}
function normArray(array, output) {
var length = array.length;
for (var i = 0; i < length; i++) {
var item = array[i];
processItem(item, output);
}
return output;
}
function classes() {
return eachTrue(normArray(arguments, {}), function (name, result) {
return result ? result + " " + name : name;
}, '');
}
return classes;
})));
//# sourceMappingURL=classes.umd.js.map