1 | // Type definitions for jsonpath 0.2.11
|
2 | // Project: https://www.npmjs.org/package/jsonpath
|
3 | // Definitions by: Hiroki Horiuchi <https://github.com/horiuchi>, Ika <https://github.com/ikatyang>
|
4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
5 |
|
6 | type PathComponent = string | number;
|
7 |
|
8 | /**
|
9 | * Find elements in `obj` matching `pathExpression`. Returns an array of elements that
|
10 | * satisfy the provided JSONPath expression,or an empty array if none were matched.
|
11 | * Returns only first `count` elements if specified.
|
12 | */
|
13 | export declare function query(obj: any, pathExpression: string, count?: number): any[];
|
14 |
|
15 | /**
|
16 | * Find paths to elements in `obj` matching `pathExpression`. Returns an array of
|
17 | * element paths that satisfy the provided JSONPath expression. Each path is itself an
|
18 | * array of keys representing the location within `obj` of the matching element. Returns
|
19 | * only first `count` paths if specified.
|
20 | */
|
21 | export declare function paths(obj: any, pathExpression: string, count?: number): PathComponent[][];
|
22 |
|
23 | /**
|
24 | * Find elements and their corresponding paths in `obj` matching `pathExpression`.
|
25 | * Returns an array of node objects where each node has a `path` containing an array of
|
26 | * keys representing the location within `obj`, and a `value` pointing to the matched
|
27 | * element. Returns only first `count` nodes if specified.
|
28 | */
|
29 | export declare function nodes(obj: any, pathExpression: string, count?: number): { path: PathComponent[]; value: any; }[];
|
30 |
|
31 | /**
|
32 | * Returns the value of the first element matching `pathExpression`. If `newValue` is
|
33 | * provided, sets the value of the first matching element and returns the new value.
|
34 | */
|
35 | export declare function value(obj: any, pathExpression: string): any;
|
36 | export declare function value<T>(obj: any, pathExpression: string, newValue: T): T;
|
37 |
|
38 | /**
|
39 | * Returns the parent of the first matching element.
|
40 | */
|
41 | export declare function parent(obj: any, pathExpression: string): any;
|
42 |
|
43 | /**
|
44 | * Runs the supplied function `fn` on each matching element, and replaces each
|
45 | * matching element with the return value from the function. The function accepts the
|
46 | * value of the matching element as its only parameter. Returns matching nodes with
|
47 | * their updated values.
|
48 | */
|
49 | export declare function apply(obj: any, pathExpression: string, fn: (x: any) => any): { path: PathComponent[]; value: any; }[];
|
50 |
|
51 | /**
|
52 | * Parse the provided JSONPath expression into path components and their associated
|
53 | * operations.
|
54 | */
|
55 | export declare function parse(pathExpression: string): any[];
|
56 |
|
57 | /**
|
58 | * Returns a path expression in string form, given a path. The supplied path may either
|
59 | * be a flat array of keys, as returned by `jp.nodes` for example, or may alternatively be a
|
60 | * fully parsed path expression in the form of an array of path components as returned
|
61 | * by `jp.parse`.
|
62 | */
|
63 | export declare function stringify(path: PathComponent[]): string;
|
64 |
|
65 | export as namespace jsonpath;
|