UNPKG

css-deadweigth

Version:

CLI tool to detect unused CSS in your project

20 lines (17 loc) 538 B
// lib/utils.js export function wildcardToRegex(wildcard) { // Escape regex special chars except * const escaped = wildcard.replace(/[-\/\\^$+?.()|[\]{}]/g, '\\$&'); const regexStr = '^' + escaped.replace(/\*/g, '.*') + '$'; return new RegExp(regexStr); } export function isIgnored(selector, ignorePatterns) { return ignorePatterns.some(pattern => { if (pattern.includes('*')) { const regex = wildcardToRegex(pattern); return regex.test(selector); } else { return selector === pattern; } }); }