
Product
Socket Now Protects the Chrome Extension Ecosystem
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
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 99 weekly downloads. As such, css-ast-iterations popularity was classified as not 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.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.