Gathering detailed insights and metrics for css-node-extract
Gathering detailed insights and metrics for css-node-extract
Gathering detailed insights and metrics for css-node-extract
Gathering detailed insights and metrics for css-node-extract
mini-css-extract-plugin
extracts CSS into separate files
postcss-modules-extract-imports
A CSS Modules transform to extract local aliases for inline imports
extract-from-css
Extract information from CSS code
optimize-css-assets-webpack-plugin
A Webpack plugin to optimize \ minimize CSS assets.
npm install css-node-extract
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
128 Commits
1 Forks
3 Watching
12 Branches
1 Contributors
Updated on 21 Aug 2023
JavaScript (62.1%)
SCSS (31.2%)
Less (6.7%)
Cumulative downloads
Total Downloads
Last day
1.2%
17,172
Compared to previous day
Last week
-7.1%
90,586
Compared to previous week
Last month
10.8%
407,910
Compared to previous month
Last year
-1.7%
4,740,948
Compared to previous year
Extract certain nodes from CSS code.
@media
, @supports
, @mixin
,...$variable
, @variable
,...@function
@mixin
and .less-mixin-selector()
.class-selector
, #id-selector
,...$sass-variable
and @less-variable
1const cssNodeExtract = require('css-node-extract'); 2const postcssScssSyntax = require('postcss-scss'); 3 4const options = { 5 // CSS source code as string. 6 css: '$variable: "value"; .selector { } .other-selector { }', 7 // Extract only variables. 8 filters: ['variables'], 9 // postcss syntax plugin to add support for SCSS code. 10 postcssSyntax: postcssScssSyntax 11}; 12 13// Asynchronous: 14cssNodeExtract.process(options).then((extractedCss) => { 15 console.log(extractedCss); // Outputs: '$variable: "value";'. 16}); 17 18// Synchronous: 19const extractedCss = cssNodeExtract.processSync(options); 20console.log(extractedCss); // Outputs: '$variable: "value";'.
1const cssNodeExtract = require('css-node-extract'); 2 3const options = { 4 // CSS source code as string. 5 css: '@keyframes { } .selector { } .other-selector { }', 6 filters: ['my-keyframe-filter'], 7 customFilters: { 8 myKeyframeFilter: [ 9 [ 10 { property: 'type', value: 'atrule' }, 11 { property: 'name', value: 'keyframes' } 12 ] 13 ] 14 } 15}; 16 17cssNodeExtract.process(options).then((extractedCss) => { 18 console.log(extractedCss); // Outputs: '@keyframes { }'. 19});
Usually css-node-extract
removes all nodes which do not match the given filters. However under some circumstances it might be useful to preserve the original line numbers (e.g. to keep source map references intact).
1const cssNodeExtract = require('css-node-extract'); 2 3const options = { 4 css: '$variable: "value"; .selector { } .other-selector { }', 5 filters: ['variables'], 6 postcssSyntax: postcssScssSyntax, 7 preserveLines: true 8}; 9 10cssNodeExtract.process(options).then((extractedCss) => { 11 // Outputs the extracted nodes with empty lines where 12 // other nodes got removed to preserve line numbers. 13 console.log(extractedCss); 14});
1import { process, processSync } from 'css-node-extract'; 2import postcssScssSyntax from 'postcss-scss'; 3 4const options = { 5 // CSS source code as string. 6 css: '$variable: "value"; .selector { } .other-selector { }', 7 // Extract only variables. 8 filters: ['variables'], 9 // postcss syntax plugin to add support for SCSS code. 10 postcssSyntax: postcssScssSyntax 11}; 12 13// Asynchronous: 14process(options).then((extractedCss) => { 15 console.log(extractedCss); // Outputs: '$variable: "value";'. 16}); 17 18// Synchronous: 19processSync(options); 20console.log(extractedCss); // Outputs: '$variable: "value";'.
With version 2.0.0 the handling of custom filters was changed. The customFilter
option was renamed to customFilters
and this option now takes an object instead of an array. Instead of defining one custom filter named custom
, you can now define unlimited custom filters with custom names.
With version 1.0.0 the filterNames
option was renamed to filters
.
1// New 2const options = { 3 css: '$variable: "value"; .selector { } .other-selector { }', 4 filters: ['variables'], 5 postcssSyntax: postcssScssSyntax 6}; 7 8// Old 9const options = { 10 css: '$variable: "value"; .selector { } .other-selector { }', 11 filterNames: ['variables'], 12 postcssSyntax: postcssScssSyntax 13};
See CONTRIBUTING.md
1npm test
Markus Oberlehner
Website: https://markus.oberlehner.net
Twitter: https://twitter.com/MaOberlehner
PayPal.me: https://paypal.me/maoberlehner
Patreon: https://www.patreon.com/maoberlehner
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/16 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
18 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
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