
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
css-simple-parser
Advanced tools
A (S)CSS parser that's tiny, blazing fast and (too) simple.
The big caveat is that this is not a full-blown CSS parser, it can only parse (S)CSS strings with the following limitations:
@charset
, @import
etc.{
, }
or ;
can be used inside strings, e.g. div[attr=";{}"]
, content: "{}"
etc.npm install css-simple-parser
The AST (Abstract Syntax Tree) provided by this library has the following shape:
type AST = ROOT_NODE;
type ROOT_NODE = {
parent: null,
children: NODE[]
};
type NODE = {
parent: ROOT_NODE | NODE,
index: number,
indexEnd: number,
selector: string,
selectorIndex: number,
selectorIndexEnd: number,
body: string,
bodyIndex: number,
bodyIndexEnd: number,
children: NODE[]
};
Parser.parse
This method computes an AST from the given CSS string.
import Parser from 'css-simple-parser';
const ast = Parser.parse ( '.foo {}' );
Parser.stringify
This method computes a CSS string given an AST.
import Parser from 'css-simple-parser';
const ast = Parser.parse ( '.foo {}' );
const css = Parser.stringify ( ast );
Parser.traverse
This method calls a function with each node found in the AST, the AST is being traversed depth-first.
import Parser from 'css-simple-parser';
const ast = Parser.parse ( '.foo {}' );
Parser.traverse ( ast, node => {
console.log ( node.selector );
});
&
placeholders are supported too.MIT © Fabio Spampinato
FAQs
A (S)CSS parser that's tiny, blazing fast and (too) simple.
The npm package css-simple-parser receives a total of 636 weekly downloads. As such, css-simple-parser popularity was classified as not popular.
We found that css-simple-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.