findAll(ast: any, matcher: (node: any) => boolean): any[]
Search the ast tree and return all matches
// find the first ast declaration node which name is 'aspect-ratio'import { findAll, EnumToken, transform } from "@tbela99/css-parser";import type { AstNode } from "@tbela99/css-parser";const css = `button { aspect-ratio: 1; width: if(media(any-pointer: fine): 30px; else: 44px);} `;// find declaration which contain a '30px' const nodeMatcher = (node: AstNode) => return node.typ == EnumToken.DeclarationNodeType && (node as AstDeclaration).nam == 'aspect-ratio'; const result = await transform(css); const nodes = findAll(result.ast, nodeMatcher); console.log({nodes}); Copy
// find the first ast declaration node which name is 'aspect-ratio'import { findAll, EnumToken, transform } from "@tbela99/css-parser";import type { AstNode } from "@tbela99/css-parser";const css = `button { aspect-ratio: 1; width: if(media(any-pointer: fine): 30px; else: 44px);} `;// find declaration which contain a '30px' const nodeMatcher = (node: AstNode) => return node.typ == EnumToken.DeclarationNodeType && (node as AstDeclaration).nam == 'aspect-ratio'; const result = await transform(css); const nodes = findAll(result.ast, nodeMatcher); console.log({nodes});
ast: any
matcher: (node: any) => boolean
Search the ast tree and return all matches