
Security News
npm ‘is’ Package Hijacked in Expanding Supply Chain Attack
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
css-ast-iterations
Advanced tools
Provide a very simple API for complex iterations on the CSS abstract syntax tree (AST).
:smile::green_heart::evergreen_tree: Provide a very simple API for complex iterations on the CSS abstract syntax tree (AST).
$ npm install css --save
$ npm install css-ast-iterations --save
const css = require('css');
const addIterations = require('css-ast-iterations');
// Create the AST
const stylesheet = css.parse('.foo {color: #fff;} .bar { width: 50px;}');
// Add all methods for iterations
addIterations(stylesheet);
// Use a findRules method for find and iterates on all Rules
stylesheet.findRules((rule, ruleIndex) => {
console.log(rule);
});
View the CSS AST Explorer.
Find and iterates on all Rules:
stylesheet.findAllRules((rule, ruleIndex) => {
console.log(rule);
});
Find and iterates on all Rules (filter by rule rules):
stylesheet.findAllRulesByType('rule', (rule, ruleIndex) => {
console.log(rule);
});
Find and iterates on all Rules (filter by import rules):
stylesheet.findAllRulesByType('import', (rule, ruleIndex) => {
console.log(rule);
});
Find and iterates on all Rules (filter by comment rules):
stylesheet.findAllRulesByType('comment', (rule, ruleIndex) => {
console.log(rule);
});
Find and iterates on all Selectors:
stylesheet.findAllSelectors((selectors, selectorIndex) => {
console.log(selectors);
});
Find and iterates on all imports:
stylesheet.findAllImport((url) => {
console.log(url);
});
Find and iterates on all Declarations:
stylesheet.findAllDeclarations((declaration) => {
console.log(declaration.property);
console.log(declaration.value);
});
Find and iterates on all Declarations (filter by selectors):
stylesheet.findAllDeclarationsBySelectors('.foo', (declaration) => {
console.log(declaration.property);
console.log(declaration.value);
});
Find and iterates on all Declarations (filter by property):
stylesheet.findAllDeclarationsByProperty('max-width', (declaration) => {
console.log(declaration.property);
console.log(declaration.value);
});
Find and iterates on all Declarations (filter by value):
stylesheet.findAllDeclarationsByValue('500px', (declaration) => {
console.log(declaration.property);
console.log(declaration.value);
});
Find and iterates on Declarations:
// Stylesheet Level (root)
stylesheet.findAllRulesByType('rule', (rule, ruleIndex) => {
// Rule Level
rule.findDeclarations((declaration, declarationIndex) => {
console.log(declaration);
});
});
Find and iterates on Declarations (filter by selectors):
// Stylesheet Level (root)
stylesheet.findAllRulesByType('rule', (rule, ruleIndex) => {
// Rule Level
rule.findDeclarationsBySelectors('.foo', (declaration, declarationIndex) => {
console.log(declaration);
});
});
Find and iterates on Declarations (filter by property):
// Stylesheet Level (root)
stylesheet.findAllRulesByType('rule', (rule, ruleIndex) => {
// Rule Level
rule.findDeclarationsByProperty('max-width', (declaration, declarationIndex) => {
console.log(declaration);
});
});
Find and iterates on Declarations (filter by value):
// Stylesheet Level (root)
stylesheet.findAllRulesByType('rule', (rule, ruleIndex) => {
// Rule Level
rule.findDeclarationsByValue('500px', (declaration, declarationIndex) => {
console.log(declaration);
});
});
Add a new declaration:
// Stylesheet Level (root)
stylesheet.findAllRulesByType('rule', (rule, ruleIndex) => {
// Rule Level
rule.findDeclarationsByProperty('max-width', (declaration, declarationIndex) => {
// Declarations Level
rule.addDeclaration('width', '50px', declarationIndex);
});
});
Remove a declaration:
// Stylesheet Level (root)
stylesheet.findAllRulesByType('rule', (rule, ruleIndex) => {
// Rule Level
rule.findDeclarationsByProperty('max-width', (declaration, declarationIndex) => {
// Declarations Level
rule.removeDeclaration(declarationIndex);
});
});
Get a specific param from a value:
// Stylesheet Level (root)
stylesheet.findAllRulesByType('rule', (rule, ruleIndex) => {
// Rule Level
rule.findDeclarationsByProperty('max-width', (declaration, declarationIndex) => {
// Declarations Level
declaration.getParam(0); // position of param
});
});
Follow the NodeJS code style guide.
Validate the code style with ESLint:
$ npm run eslint
Run the unit tests with mocha:
$ npm test
Calculate the coverage with Istanbul:
$ npm run cover
To keep better organization of releases we follow the Semantic Versioning 2.0.0 guidelines.
Find on our issues the next steps of the project ;)
Want to contribute? Follow these recommendations.
See Releases for detailed changelog.
FAQs
Provide a very simple API for complex iterations on the CSS abstract syntax tree (AST).
The npm package css-ast-iterations receives a total of 1,304 weekly downloads. As such, css-ast-iterations popularity was classified as popular.
We found that css-ast-iterations demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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 ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Security News
A critical flaw in the popular npm form-data package could allow HTTP parameter pollution, affecting millions of projects until patched versions are adopted.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.