My code accurately identifies CSS selectors within a string as shown below:
let selectors = index.toString().match(/\.-?[_a-zA-Z]+[\w-]*(?=[^{}]*\{)/g);
This method successfully matches css selectors like u-background-color-navajo-white
in declarations such as:
.u-background-color-navajo-white {
background-color: NavajoWhite !important;
background-color: var(--color-navajo-white) !important;
}
However, the expression also picks up top-level domains mentioned within comments in the CSS file, for example .com, .io, .org,
, etc.
If anyone has suggestions on how to modify the regex pattern to exclude these domain names?
Testing Repository
git clone https://github.com/superflycss/utilities-layout
npm i
sfc build
node duplicates.1.js
The output will be:
ole@mki:~/SuperflyCSS/utilities-layout$ node duplicates.1.js
[ '.com',
'.com',
'.io',
'.io',
'.io',
'.md',
'.org',
'.org',
'.org',
'.w3',
'.w3',
'.w3' ]
Support for CLI
The issue has now been resolved. I am planning to integrate this script into the @superflycss/cli in the upcoming period for those who require a postcss builder / duplicates checker.