"use strict"; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.bemmy = void 0; /** * Creates and returns a function to format CSS classes following the {@link http://getbem.com/naming|BEM Convention} * @param [block] - {@link https://getbem.com/naming/#Block:~:text=of%20the%20website.-,Block,-Encapsulates%20a%20standalone|Block name} (standalone entity that is meaningful on its own) * @returns {(element?: string, modifiers?: string | Array. | object, ...additionalClasses?:string) => string} Function that accepts {@link https://getbem.com/naming/#Block:~:text=block%20%7B%20color%3A%20%23042%3B%20%7D-,Element,-Parts%20of%20a|element} / {@link https://getbem.com/naming/#Block:~:text=%23042%3B%20%7D-,Modifier,-Flags%20on%20blocks|modifier} name arguments * @example * ```ts * import bemmy from 'bemmy'; * const bem = bemmy('component') * * // block * bem() * // -> 'component' * * // block + element * bem('content') * // -> 'component__content' * * // block + modifier * bem(null, 'disabled') * // -> 'component component--disabled' * * // block + element + modifier * bem('content', 'disabled') * // -> 'component__content component__content--disabled' * * // multiple modifiers (object or array) * bem('content', { tall: true, green: true }) * // -> 'component__content component__content--tall component__content--green' * bem('content', ['tall', 'green']) * // -> 'component__content component__content--tall component__content--green' * * // dynamic modifiers * const props = { * tall: false, * green: undefined, * wide: true * custom: 1 > 2 // some expression that resolves to true or false * }; * bem('content', props) * // -> 'component__content component__content--wide' * * // additional classes * bem(null, null, 'some-class', 'another-class') * // -> 'component some-class another-class' * ``` */ var bemmy = function (block) { if (block === void 0) { block = ''; } return function (element, modifiers) { var additionalClasses = []; for (var _i = 2; _i < arguments.length; _i++) { additionalClasses[_i - 2] = arguments[_i]; } var _element = element ? "__".concat(element) : ''; var _modifiers = []; if (modifiers) { if (typeof modifiers === 'string') { _modifiers = [modifiers]; } else if (Array.isArray(modifiers)) { _modifiers = modifiers.filter(isValidString); } else if (typeof modifiers === 'object' && !Array.isArray(modifiers)) { _modifiers = Object.keys(modifiers).filter(function (key) { return modifiers[key]; }); } } var classArr = __spreadArray(__spreadArray([ "".concat(block).concat(_element) ], _modifiers.reduce(function (acc, modifier) { acc.push("".concat(block).concat(_element, "--").concat(modifier)); return acc; }, []), true), additionalClasses.filter(Boolean), true); return classArr.join(' '); }; }; exports.bemmy = bemmy; function isValidString(val) { return typeof val === 'string' && val !== ''; } exports.default = exports.bemmy;