UNPKG

classjoin

Version:

A bit simpler utility for conditionally joining classNames together

25 lines (21 loc) 686 B
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global.classJoin = factory()); }(this, (function () { 'use strict'; function classJoin(withConditions, withoutConditions) { var classes = []; var keys = Object.keys(withConditions); for (var i = 0, n = keys.length; i < n; i++) { var key = keys[i]; if (withConditions[key]) { classes.push(key); } } if (withoutConditions) { classes = withoutConditions.concat(classes); } return classes.join(' '); } return classJoin; })));