findLast(ast: any, matcher: (node: any) => boolean): any
Search the ast tree and return the last match.
// find the first ast declaration node which name is 'aspect-ratio'import { findLast, 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 node = findLast(result.ast, nodeMatcher); console.log({node}); Copy
// find the first ast declaration node which name is 'aspect-ratio'import { findLast, 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 node = findLast(result.ast, nodeMatcher); console.log({node});
ast: any
matcher: (node: any) => boolean
Search the ast tree and return the last match.