New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

purgecss-whitelister

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

purgecss-whitelister - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0

30

index.js
const { parse } = require('scss-parser') // https://github.com/salesforce-ux/scss-parser
const parse2 = require('gonzales-pe').parse
const { readFileSync } = require('fs')

@@ -7,2 +8,3 @@ const globAll = require('glob-all')

const shouldKeep = ['id', 'class', 'attribute']
const shouldKeep2 = ['id', 'class', 'attribute', 'typeSelector']
const exts = ['css', 'sass', 'scss', 'less']

@@ -20,6 +22,28 @@

// File contents.
const fileContents = readFileSync(filename, 'utf-8')
const parsedData = parse(fileContents).value
const selectors = parseStyleAST(parsedData)
return acc.concat(selectors)
// 1st try `scss-parser`.
try {
// throw 'nope'
const parsedData = parse(fileContents).value
const selectors = parseStyleAST(parsedData)
return acc.concat(selectors)
// 2nd try `gonzales-pe`.
} catch(e) {
const parsed = parse2(fileContents, { syntax: ext })
const nodes = []
// Built-in traversal method, no need to recursively
// traverse the tree, cherry pick, and flatten the results!
parsed.traverse(node => {
if (shouldKeep2.includes(node.type)) {
const thing = node.content.find(({ type }) => type === 'ident')
if (thing) nodes.push(thing.content)
}
})
return [...acc, ...new Set(nodes)]
}
}, [])

@@ -26,0 +50,0 @@

3

package.json
{
"name": "purgecss-whitelister",
"version": "2.0.1",
"version": "2.1.0",
"description": "A utility for creating whitelists of CSS selectors for use with Purgecss.",

@@ -17,4 +17,5 @@ "main": "index.js",

"glob-all": "^3.1.0",
"gonzales-pe": "^4.2.3",
"scss-parser": "^1.0.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc