@finnair/path
Version:
Simple object path as array of strings and numbers
46 lines (45 loc) • 1.62 kB
TypeScript
import { Path, PathComponent } from './Path.js';
type Continue = boolean;
export interface MatchHandler {
(value: any, component: PathComponent): Continue;
}
export interface PathExpression {
find(current: any, callback: MatchHandler): Continue;
test(component: PathComponent): boolean;
readonly allowGaps: boolean;
toString(): string;
}
export declare function isPathExpression(component: PathComponent | PathExpression): component is PathExpression;
export interface Node {
readonly path: Path;
readonly value: any;
}
export declare class IndexMatcher implements PathExpression {
private readonly index;
readonly allowGaps = true;
constructor(index: number);
find(current: any, callback: MatchHandler): Continue;
test(component: PathComponent): boolean;
toString(): string;
}
export declare class PropertyMatcher implements PathExpression {
private readonly property;
readonly allowGaps = false;
constructor(property: string);
find(current: any, callback: MatchHandler): Continue;
test(component: PathComponent): boolean;
toString(): string;
}
export declare class UnionMatcher implements PathExpression {
private readonly components;
constructor(components: PathComponent[]);
find(current: any, callback: MatchHandler): Continue;
test(component: PathComponent): boolean;
get allowGaps(): boolean;
toString(): string;
static of(...components: PathComponent[]): UnionMatcher;
private propertyToString;
}
export declare const AnyIndex: PathExpression;
export declare const AnyProperty: PathExpression;
export {};