Gathering detailed insights and metrics for @mapbox/postcss-html-filter
Gathering detailed insights and metrics for @mapbox/postcss-html-filter
Gathering detailed insights and metrics for @mapbox/postcss-html-filter
Gathering detailed insights and metrics for @mapbox/postcss-html-filter
Filter CSS through HTML, removing selectors that do not apply to the HTML
npm install @mapbox/postcss-html-filter
Typescript
Module System
Min. Node Version
Node Version
NPM Version
64.8
Supply Chain
87.2
Quality
82.6
Maintenance
100
Vulnerability
99.6
License
JavaScript (100%)
Total Downloads
61,185
Last Day
3
Last Week
29
Last Month
90
Last Year
2,420
MIT License
11 Stars
36 Commits
3 Forks
110 Watchers
2 Branches
593 Contributors
Updated on Apr 16, 2024
Latest Version
3.0.0
Package Id
@mapbox/postcss-html-filter@3.0.0
Unpacked Size
16.30 kB
Size
6.28 kB
File Count
12
NPM Version
9.6.6
Node Version
18.15.0
Published on
Oct 30, 2023
Cumulative downloads
Total Downloads
Last Day
0%
3
Compared to previous day
Last Week
26.1%
29
Compared to previous week
Last Month
-66%
90
Compared to previous month
Last Year
-35.4%
2,420
Compared to previous year
1
6
Filter CSS through HTML, removing selectors that do not apply to that HTML.
Parses HTML with Cheerio — using its jQuery-like selector queries — to determine which selectors in the CSS correspond to actual elements on the page. Removes selectors that have no corresponding elements, rules that have no corresponding selectors, at-rules containing no corresponding rules, etc.
Also, for good measure, runs the CSS through postcss-discard-unused, which removes unused @counter-style
, @keyframes
, and @font-face
at-rules.
npm install @mapbox/postcss-html-filter
Follow the instructions for your PostCSS runner.
This example uses PostCSS's Node API:
1const postcss = require('postcss'); 2const postcssHtmlFilter = require('@mapbox/postcss-html-filter'); 3const fs = require('fs'); 4 5const myHtml = fs.readFileSync('path/to/some.html', 'utf8'); 6postcss() 7 .use(postcssHtmlFilter({ html: myHtml }) 8 .then(result => { /* ... */ });
Type: string
.
Required.
The HTML that you will use to filter your CSS.
::before
, ::first-line
).
If the selector applies without them, we can assume that it also applies with them, and the selector should be kept.
Pseudo-classes (e.g. :first-child
, :not(a)
, :nth-child(3)
) are passed to Cheerio when Cheerio can interpret them (using css-select).
If the pseudo-class cannot be interpreted by Cheerio, it is stripped before the selector is checked.Kind of. This is essentially a simplified version of what UnCSS does. Instead of using PhantomJS or jsdom to load the page, size things, download resources, etc., this module only addresse the core problem of filtering out CSS that is not used in some HTML. This is a low-level module that could be used within other, higher-level projects (e.g. ones that download resources).
The tests are very simple. In fact, there's just one Jest snapshot test at the moment, which provides 100% code coverage. We can add more to the CSS and HTML fixtures, as needed, to test other scenarios and code changes; and Jest handles the comparison and offers a nice legible read-out of what went wrong.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
branch protection is not maximal on development and all release branches
Details
Reason
6 existing vulnerabilities detected
Details
Reason
Found 3/25 approved changesets -- score normalized to 1
Reason
project is archived
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-05-05
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More