tailwindcss-mangle-shared
Advanced tools
Comparing version 1.2.3 to 1.2.4
@@ -6,21 +6,20 @@ 'use strict'; | ||
const defaultMangleClassFilter = (className) => { | ||
return /[-:]/.test(className); | ||
return /[:-]/.test(className); | ||
}; | ||
function groupBy(arr, cb) { | ||
if (!Array.isArray(arr)) { | ||
throw new Error('expected an array for first argument'); | ||
throw new TypeError('expected an array for first argument'); | ||
} | ||
if (typeof cb !== 'function') { | ||
throw new Error('expected a function for second argument'); | ||
throw new TypeError('expected a function for second argument'); | ||
} | ||
const result = {}; | ||
for (let i = 0; i < arr.length; i++) { | ||
const item = arr[i]; | ||
for (const item of arr) { | ||
const bucketCategory = cb(item); | ||
const bucket = result[bucketCategory]; | ||
if (!Array.isArray(bucket)) { | ||
result[bucketCategory] = [item]; | ||
if (Array.isArray(bucket)) { | ||
result[bucketCategory].push(item); | ||
} | ||
else { | ||
result[bucketCategory].push(item); | ||
result[bucketCategory] = [item]; | ||
} | ||
@@ -30,5 +29,5 @@ } | ||
} | ||
const acceptChars = 'abcdefghijklmnopqrstuvwxyz'.split(''); | ||
const acceptChars = [...'abcdefghijklmnopqrstuvwxyz']; | ||
function stripEscapeSequence(words) { | ||
return words.replace(/\\/g, ''); | ||
return words.replaceAll('\\', ''); | ||
} | ||
@@ -40,6 +39,6 @@ const validate = (opts, classGenerator) => { | ||
const c = classGenerator.newClassMap[className]; | ||
if (c.usedBy.length >= 1) { | ||
if (c.usedBy.length > 0) { | ||
continue; | ||
} | ||
if (c.usedBy[0].match(/.+\.css:*$/)) { | ||
if (/.+\.css:*$/.test(c.usedBy[0])) { | ||
console.log(`The class name '${className}' is not used: defined at ${c.usedBy[0]}.`); | ||
@@ -60,4 +59,3 @@ } | ||
if (Array.isArray(arr)) { | ||
for (let i = 0; i < arr.length; i++) { | ||
const item = arr[i]; | ||
for (const item of arr) { | ||
if (typeof item === 'string') { | ||
@@ -118,17 +116,7 @@ if (item === str) { | ||
const { include } = this.opts; | ||
if (Array.isArray(include)) { | ||
return regExpTest(include, filePath); | ||
} | ||
else { | ||
return true; | ||
} | ||
return Array.isArray(include) ? regExpTest(include, filePath) : true; | ||
} | ||
excludeFilePath(filePath) { | ||
const { exclude } = this.opts; | ||
if (Array.isArray(exclude)) { | ||
return regExpTest(exclude, filePath); | ||
} | ||
else { | ||
return false; | ||
} | ||
return Array.isArray(exclude) ? regExpTest(exclude, filePath) : false; | ||
} | ||
@@ -182,9 +170,11 @@ isFileIncluded(filePath) { | ||
} | ||
return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d'); | ||
return str.replaceAll(/[$()*+.?[\\\]^{|}]/g, '\\$&').replaceAll('-', '\\x2d'); | ||
} | ||
function makeRegex(str) { | ||
return new RegExp('(?<=^|[\\s"])' + escapeStringRegexp(str), 'g'); | ||
function makeRegex(str, options = { | ||
exact: true | ||
}) { | ||
return new RegExp('(?<=^|[\\s"])' + escapeStringRegexp(str) + (options.exact ? '(?=$|[\\s"])' : ''), 'g'); | ||
} | ||
const validateFilterRE = /[\w\u00A0-\uFFFF-_:%-?]/; | ||
const validateFilterRE = /[\w%-?\u00A0-\uFFFF-]/; | ||
function isValidSelector(selector = '') { | ||
@@ -194,4 +184,4 @@ return validateFilterRE.test(selector); | ||
const splitCode = (code, options = { splitQuote: true }) => { | ||
const regex = options.splitQuote ? /[\s"]+/ : /[\s]+/; | ||
return code.split(regex).filter(isValidSelector); | ||
const regex = options.splitQuote ? /[\s"]+/ : /\s+/; | ||
return code.split(regex).filter((x) => isValidSelector(x)); | ||
}; | ||
@@ -198,0 +188,0 @@ |
export declare function escapeStringRegexp(str: string): string; | ||
export declare function makeRegex(str: string): RegExp; | ||
export declare function makeRegex(str: string, options?: { | ||
exact: boolean; | ||
}): RegExp; |
{ | ||
"name": "tailwindcss-mangle-shared", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "The shared utils of tailwindcss-mangle", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
15859
421