From d63b2c465829afeb9e18a356f1652f0a580c5bf1 Mon Sep 17 00:00:00 2001 From: Maximilian Brandau Date: Thu, 4 Oct 2018 14:48:39 +0200 Subject: [PATCH] Run prettier and build --- lib/index.js | 14 ++++++++------ src/idGenerator.js | 6 +++--- src/index.js | 29 ++++++++++++++++++++--------- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/lib/index.js b/lib/index.js index 8b0b8b4..5058845 100644 --- a/lib/index.js +++ b/lib/index.js @@ -23,10 +23,10 @@ var CssShortener = function CssShortener(options) { orig = capturingGroup.substr(1); // Remove dot infront of class name // If the ignorePrefix option is set and the current class starts with the prefix, trim the prefix off and ignore the class. - if (t._options.ignorePrefix && orig.startsWith(t._options.ignorePrefix)) return t._options.trimIgnorePrefix ? ".".concat(orig.substr(t._options.ignorePrefix.length)) : ".".concat(orig); - if (t._classNameMap[orig] != null) id = t._classNameMap[orig]; // Use mapped class name - else id = t._classNameMap[orig] = t._idGenerator(); // Generate and map new class name + if (t._options.ignorePrefix && orig.startsWith(t._options.ignorePrefix)) return t._options.trimIgnorePrefix ? ".".concat(orig.substr(t._options.ignorePrefix.length)) : ".".concat(orig); // Use already mapped class name + if (t._classNameMap[orig] != null) id = t._classNameMap[orig]; // Generate and map new class name + else id = t._classNameMap[orig] = t._idGenerator(); return ".".concat(id); }; @@ -52,7 +52,8 @@ var CssShortener = function CssShortener(options) { this.importMap = function (map, override) { for (var orig in map) { if (this._classNameMap[orig] != null) { - if (override === true) this._classNameMap[orig] = map[orig]; // Override mapped class name + // Override mapped class name + if (override === true) this._classNameMap[orig] = map[orig]; } else this._classNameMap[orig] = map[orig]; // Import class name } @@ -62,8 +63,9 @@ var CssShortener = function CssShortener(options) { return replaceStream(CLASS_NAME_REGEX, replaceCss); }; - this.replaceCss = function (css) { - return css.replace(CLASS_NAME_REGEX, replaceCss); + this.replaceCss = function (css, sourceMap) { + var replacedCss = css.replace(CLASS_NAME_REGEX, replaceCss); + return replacedCss; }; this.htmlStream = function () { diff --git a/src/idGenerator.js b/src/idGenerator.js index 370f8f0..b2d0f19 100644 --- a/src/idGenerator.js +++ b/src/idGenerator.js @@ -12,8 +12,8 @@ var IdGenerator = function(alphabet) { var res = generateId(options); while (/^[0-9-].*$/.test(res)) res = generateId(options); return res; - } -} + }; +}; var generateId = function(options) { var res = ''; @@ -31,6 +31,6 @@ var generateId = function(options) { } return res; -} +}; module.exports = IdGenerator; diff --git a/src/index.js b/src/index.js index d0cb9bf..17f6616 100644 --- a/src/index.js +++ b/src/index.js @@ -7,8 +7,10 @@ const HTML_CLASS_REGEX = /class="([\w-\s]*)"/g; const CssShortener = function(options) { if (!options) options = {}; this._options = options; - if (!this._options.hasOwnProperty('ignorePrefix')) this._options.ignorePrefix = 'ignore-'; - if (!this._options.hasOwnProperty('trimIgnorePrefix')) this._options.trimIgnorePrefix = true; + if (!this._options.hasOwnProperty('ignorePrefix')) + this._options.ignorePrefix = 'ignore-'; + if (!this._options.hasOwnProperty('trimIgnorePrefix')) + this._options.trimIgnorePrefix = true; this._idGenerator = new IdGenerator(this._options.alphabet); this._classNameMap = {}; @@ -20,10 +22,14 @@ const CssShortener = function(options) { // If the ignorePrefix option is set and the current class starts with the prefix, trim the prefix off and ignore the class. if (t._options.ignorePrefix && orig.startsWith(t._options.ignorePrefix)) - return t._options.trimIgnorePrefix ? `.${orig.substr(t._options.ignorePrefix.length)}` : `.${orig}`; + return t._options.trimIgnorePrefix + ? `.${orig.substr(t._options.ignorePrefix.length)}` + : `.${orig}`; - if (t._classNameMap[orig] != null) id = t._classNameMap[orig]; // Use mapped class name - else id = t._classNameMap[orig] = t._idGenerator(); // Generate and map new class name + // Use already mapped class name + if (t._classNameMap[orig] != null) id = t._classNameMap[orig]; + // Generate and map new class name + else id = t._classNameMap[orig] = t._idGenerator(); return `.${id}`; }; @@ -34,7 +40,10 @@ const CssShortener = function(options) { let result = ''; for (let i = 0; i < classCount; i++) { // Check if class is mapped and add it to the result - result += (t._classNameMap[classes[i]] != null ? t._classNameMap[classes[i]] : classes[i]); + result += + t._classNameMap[classes[i]] != null + ? t._classNameMap[classes[i]] + : classes[i]; if (i < classCount - 1) result += ' '; } return `class="${result}"`; @@ -46,7 +55,8 @@ const CssShortener = function(options) { this.importMap = function(map, override) { for (let orig in map) { if (this._classNameMap[orig] != null) { - if (override === true) this._classNameMap[orig] = map[orig]; // Override mapped class name + // Override mapped class name + if (override === true) this._classNameMap[orig] = map[orig]; } else this._classNameMap[orig] = map[orig]; // Import class name } }; @@ -54,8 +64,9 @@ const CssShortener = function(options) { this.cssStream = function() { return replaceStream(CLASS_NAME_REGEX, replaceCss); }; - this.replaceCss = function(css) { - return css.replace(CLASS_NAME_REGEX, replaceCss); + this.replaceCss = function(css, sourceMap) { + const replacedCss = css.replace(CLASS_NAME_REGEX, replaceCss); + return replacedCss; }; this.htmlStream = function() { return replaceStream(HTML_CLASS_REGEX, replaceHtml);