Created
August 29, 2019 05:31
-
-
Save hail2u/77e3a20056f445f3b01bca76d030e1a6 to your computer and use it in GitHub Desktop.
List unused custom properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// list unused custom properties | |
// $ node list-unused-custom-properties.js <FILENAME> | |
const fs = require("fs"); | |
const postcss = require("postcss"); | |
const css = postcss.parse(fs.readFileSync(process.argv[2], "utf8")); | |
const customProperties = {}; | |
css.walkDecls(decl => { | |
if (decl.prop.startsWith("--")) { | |
customProperties[decl.prop] = 0; | |
} | |
const variables = decl.value.match(/\bvar\(.*?\)/g); | |
if (!variables) { | |
return; | |
} | |
variables.forEach(variable => { | |
const customProperty = variable.replace(/var\((.*?)\)/, "$1"); | |
delete customProperties[customProperty]; | |
}); | |
}); | |
console.log(customProperties); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works against a concatenated CSS file only.