UNPKG

@finnair/path

Version:
43 lines (42 loc) 1.85 kB
import { Path, PathComponent } from './Path.js'; import { Node, PathExpression, PropertyMatcher, IndexMatcher, AnyIndex, AnyProperty, UnionMatcher } from './matchers.js'; export interface ResultCollector { /** * Collect a matching path and value. Return true to continue matching or false to stop. */ (path: Path, value: any): boolean; } export declare class PathMatcher { private readonly expressions; readonly allowGaps: boolean; private constructor(); find(root: any, collector: ResultCollector): void; findAll(root: any, acceptUndefined?: boolean): Node[]; findFirst(root: any, acceptUndefined?: boolean): undefined | Node; findValues(root: any, acceptUndefined?: boolean): any[]; findFirstValue(root: any, acceptUndefined?: boolean): any; /** * Exact match: path length must match the number of expressions and all expressions must match. Only sibling paths match. * * @param path * @returns true if path is an exact match to expressions */ match(path: Path): boolean; /** * Prefix match: path length must be equal or longer than the number of expressions and all expressions must match. All sibling and child paths match. * * @param path * @returns true the start the path matches */ prefixMatch(path: Path): boolean; /** * Partial match: path length can be less than or more than the number of expressions, but all corresponding expressions must match. All parent, sibling and child paths match. * * @param path * @returns true if all path components match */ partialMatch(path: Path): boolean; toJSON(): string; static of(...path: (PathComponent | PathExpression)[]): PathMatcher; } export { AnyIndex, AnyProperty, PropertyMatcher, IndexMatcher, Node, PathExpression, UnionMatcher };