Skip to main content
Deno 2 is finally here 🎉️
Learn more
Latest
method Container.prototype.walkRules
Re-export
import { Container } from "https://deno.land/x/postcss@8.4.16/lib/postcss.js";

Traverses the container’s descendant nodes, calling callback for each rule node.

If you pass a filter, iteration will only happen over rules with matching selectors.

Like Container#each, this method is safe to use if you are mutating arrays during iteration.

const selectors = []
root.walkRules(rule => {
  selectors.push(rule.selector)
})
console.log(`Your CSS uses ${ selectors.length } selectors`)

Parameters

selectorFilter: string | RegExp

String or regular expression to filter rules by selector.

callback: (rule: Rule, index: number) => false | void

Iterator receives each node and index.

Returns

false | undefined

Returns false if iteration was broke.

Parameters

callback: (rule: Rule, index: number) => false | void

Returns

false | undefined