@gtechdoodler/bem-it
Version:
A BEM util to help with consistent element class naming in components.
1 lines • 1.96 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.addClass=exports.Output=void 0;var Output=function(){function t(t){this._lastBemIt=t}return Object.defineProperty(t.prototype,"and",{get:function(){return new BemIt(this._lastBemIt)},enumerable:!1,configurable:!0}),t.prototype.out=function(t){return this._lastBemIt.out(t)},t}();exports.Output=Output;var BemIt=function(){function t(t){this._block="",this._lastBlockObj=null,this._fullBem="","string"==typeof t?(this._block=t,this._fullBem=t):(this._lastBlockObj=t,this._fullBem=t.blockString)}return Object.defineProperty(t.prototype,"blockString",{get:function(){var t;return this._block||(null===(t=this._lastBlockObj)||void 0===t?void 0:t.blockString)||""},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"peek",{get:function(){return this._fullBem},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"and",{get:function(){return new t(this)},enumerable:!1,configurable:!0}),t.prototype.el=function(t){return this._fullBem=t?this._fullBem+"__"+t.trim():this._fullBem,this},t.prototype.mod=function(t){function e(t){return""!==(t=t?t.trim():"")?o._fullBem+("--"+t.trim()):void 0}function r(t){return t.filter(function(t){return t}).map(e).join(" ")}var n,o=this;return"string"==typeof t?t=e(t):Array.isArray(t)?t=r(t):t&&(n=[],Object.entries(t).forEach(function(t){var e=t[0];t[1]&&n.push(e)}),t=r(n)),t&&(this._fullBem=this._fullBem+" "+t),new Output(this)},t.prototype.out=function(t){void 0===t&&(t="default");var e=this._block?this._fullBem:(null===(r=this._lastBlockObj)||void 0===r?void 0:r.out())+" "+this._fullBem;if(this._fullBem=this.blockString,this._lastBlockObj=null,"last"===t){var r=e.split(" "),t=r.length;if(t)return r[t-1]}return e},t}();function addClass(e){return e=e?e.trim():void 0,{before:function(t){return(e?e+" ":"")+t.out()},after:function(t){return t.out()+(e?" "+e:"")}}}exports.default=BemIt,exports.addClass=addClass;