json-p3 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/deep_equals.d.ts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/json-p3.browser.js +109 -177
- package/dist/json-p3.browser.min.js +1 -1
- package/dist/json-p3.browser.min.js.map +1 -1
- package/dist/json-p3.cjs.js +109 -177
- package/dist/json-p3.esm.js +109 -177
- package/dist/json-p3.iife.min.js +1 -1
- package/dist/json-p3.iife.min.js.map +1 -1
- package/dist/patch/errors.d.ts +11 -0
- package/dist/patch/index.d.ts +11 -0
- package/dist/patch/patch.d.ts +161 -0
- package/dist/path/environment.d.ts +165 -0
- package/dist/path/errors.d.ts +65 -0
- package/dist/path/expression.d.ts +101 -0
- package/dist/path/extra/expression.d.ts +6 -0
- package/dist/path/extra/index.d.ts +0 -0
- package/dist/path/extra/selectors.d.ts +35 -0
- package/dist/path/functions/count.d.ts +7 -0
- package/dist/path/functions/function.d.ts +26 -0
- package/dist/path/functions/has.d.ts +44 -0
- package/dist/path/functions/index.d.ts +11 -0
- package/dist/path/functions/length.d.ts +7 -0
- package/dist/path/functions/match.d.ts +33 -0
- package/dist/path/functions/pattern.d.ts +2 -0
- package/dist/path/functions/search.d.ts +34 -0
- package/dist/path/functions/value.d.ts +7 -0
- package/dist/path/index.d.ts +76 -0
- package/dist/path/lex.d.ts +74 -0
- package/dist/path/lru_cache.d.ts +10 -0
- package/dist/path/node.d.ts +84 -0
- package/dist/path/parse.d.ts +61 -0
- package/dist/path/path.d.ts +42 -0
- package/dist/path/segments.d.ts +39 -0
- package/dist/path/selectors.d.ts +86 -0
- package/dist/path/serialize.d.ts +6 -0
- package/dist/path/token.d.ts +70 -0
- package/dist/path/types.d.ts +46 -0
- package/dist/pointer/errors.d.ts +42 -0
- package/dist/pointer/index.d.ts +24 -0
- package/dist/pointer/pointer.d.ts +106 -0
- package/dist/types.d.ts +25 -0
- package/package.json +3 -3
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { JSONValue } from "../types";
|
|
2
|
+
import { JSONPathEnvironment } from "./environment";
|
|
3
|
+
export declare const Nothing: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* ValueType for JSONPath function expression tye system.
|
|
6
|
+
*/
|
|
7
|
+
export type JSONPathValue = JSONValue | typeof Nothing;
|
|
8
|
+
/**
|
|
9
|
+
* Object passed to `FilterExpression.evaluate()`.
|
|
10
|
+
*/
|
|
11
|
+
export type FilterContext = {
|
|
12
|
+
environment: JSONPathEnvironment;
|
|
13
|
+
currentValue: JSONValue;
|
|
14
|
+
rootValue: JSONValue;
|
|
15
|
+
lazy?: boolean;
|
|
16
|
+
currentKey?: string | number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A type predicate for an object with a string property.
|
|
20
|
+
*/
|
|
21
|
+
export declare function hasStringKey(value: unknown, key: string): value is {
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
export declare const KEY_MARK = "\u0002";
|
|
25
|
+
/**
|
|
26
|
+
* Options for serializing paths.
|
|
27
|
+
*/
|
|
28
|
+
export type SerializationOptions = {
|
|
29
|
+
/**
|
|
30
|
+
* `pretty` paths always use:
|
|
31
|
+
* - shorthand notation rather than dot notation where possible
|
|
32
|
+
* - double quotes rather than single quotes for string literals and where shorthand
|
|
33
|
+
* notation is not possible
|
|
34
|
+
* - short escape sequences for common non-printing characters such as `\n` and `\t`
|
|
35
|
+
*
|
|
36
|
+
* `canonical` paths always use:
|
|
37
|
+
* - bracket notation for name and wildcard selectors
|
|
38
|
+
* - single quotes for name selectors and string literals
|
|
39
|
+
* - short escape sequences for common non-printing characters such as `\n` and `\t`
|
|
40
|
+
*
|
|
41
|
+
* `canonical` paths will produce a normalized path where available, but cannot be
|
|
42
|
+
* considered normalized paths if the query does not represent a singular, absolute node.
|
|
43
|
+
*/
|
|
44
|
+
form: "pretty" | "canonical";
|
|
45
|
+
};
|
|
46
|
+
export declare const defaultSerializationOptions: SerializationOptions;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for all JSON Pointer errors.
|
|
3
|
+
*/
|
|
4
|
+
export declare class JSONPointerError extends Error {
|
|
5
|
+
readonly message: string;
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Base class for JSON Pointer resolution errors.
|
|
10
|
+
*/
|
|
11
|
+
export declare class JSONPointerResolutionError extends JSONPointerError {
|
|
12
|
+
readonly message: string;
|
|
13
|
+
constructor(message: string);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Error thrown due to an out of range index when resolving a JSON Pointer.
|
|
17
|
+
*/
|
|
18
|
+
export declare class JSONPointerIndexError extends JSONPointerResolutionError {
|
|
19
|
+
readonly message: string;
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Error thrown due to a missing property when resolving a JSON Pointer.
|
|
24
|
+
*/
|
|
25
|
+
export declare class JSONPointerKeyError extends JSONPointerResolutionError {
|
|
26
|
+
readonly message: string;
|
|
27
|
+
constructor(message: string);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Error thrown due to invalid JSON Pointer syntax.
|
|
31
|
+
*/
|
|
32
|
+
export declare class JSONPointerSyntaxError extends JSONPointerError {
|
|
33
|
+
readonly message: string;
|
|
34
|
+
constructor(message: string);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Error thrown when trying to resolve a property or index against a primitive value.
|
|
38
|
+
*/
|
|
39
|
+
export declare class JSONPointerTypeError extends JSONPointerResolutionError {
|
|
40
|
+
readonly message: string;
|
|
41
|
+
constructor(message: string);
|
|
42
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { JSONValue } from "../types";
|
|
2
|
+
import { MaybeJSONValue } from "./pointer";
|
|
3
|
+
export { JSONPointer, RelativeJSONPointer, UNDEFINED } from "./pointer";
|
|
4
|
+
export type { MaybeJSONValue } from "./pointer";
|
|
5
|
+
export { JSONPointerError, JSONPointerResolutionError, JSONPointerIndexError, JSONPointerKeyError, JSONPointerSyntaxError, JSONPointerTypeError, } from "./errors";
|
|
6
|
+
/**
|
|
7
|
+
* Resolve JSON Pointer _pointer_ against JSON-like data _value_.
|
|
8
|
+
*
|
|
9
|
+
* @param pointer - A string representation of a JSON pointer.
|
|
10
|
+
* @param value - The target JSON-like value, possibly loaded using
|
|
11
|
+
* `JSON.parse()`.
|
|
12
|
+
* @param fallback - A default value to return if _value_ has no
|
|
13
|
+
* path matching `pointer`.
|
|
14
|
+
* @returns The value identified by _pointer_ or, if given, the fallback
|
|
15
|
+
* value in the even of a `JSONPointerResolutionError`.
|
|
16
|
+
*
|
|
17
|
+
* @throws {@link JSONPointerResolutionError}
|
|
18
|
+
* If the value pointed to by _pointer_ does not exist in _value_, and
|
|
19
|
+
* no fallback value is given.
|
|
20
|
+
*
|
|
21
|
+
* @throws {@link JSONPointerSyntaxError}
|
|
22
|
+
* If _pointer_ is malformed according to RFC 6901.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolve(pointer: string, value: JSONValue, fallback?: MaybeJSONValue): JSONValue;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { JSONValue } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* The symbol indicating the absence of a JSON value.
|
|
4
|
+
*/
|
|
5
|
+
export declare const UNDEFINED: unique symbol;
|
|
6
|
+
export type MaybeJSONValue = JSONValue | typeof UNDEFINED;
|
|
7
|
+
/**
|
|
8
|
+
* Identify a single value in JSON-like data, as per RFC 6901.
|
|
9
|
+
*/
|
|
10
|
+
export declare class JSONPointer {
|
|
11
|
+
#private;
|
|
12
|
+
tokens: string[];
|
|
13
|
+
/**
|
|
14
|
+
* @param pointer - A string representation of a JSON Pointer.
|
|
15
|
+
*/
|
|
16
|
+
constructor(pointer: string);
|
|
17
|
+
static encode(tokens: string[]): string;
|
|
18
|
+
/**
|
|
19
|
+
* Resolve this pointer against JSON-like data _value_.
|
|
20
|
+
*
|
|
21
|
+
* @param value - The target JSON-like value, possibly loaded using
|
|
22
|
+
* `JSON.parse()`.
|
|
23
|
+
* @param fallback - A default value to return if _value_ has no
|
|
24
|
+
* path matching `pointer`.
|
|
25
|
+
* @returns The value identified by _pointer_ or, if given, the fallback
|
|
26
|
+
* value in the even of a `JSONPointerResolutionError`.
|
|
27
|
+
*
|
|
28
|
+
* @throws {@link JSONPointerResolutionError}
|
|
29
|
+
* If the value pointed to by _pointer_ does not exist in _value_, and
|
|
30
|
+
* no fallback value is given.
|
|
31
|
+
*/
|
|
32
|
+
resolve(value: JSONValue, fallback?: MaybeJSONValue): JSONValue;
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param value -
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
resolveWithParent(value: JSONValue): [MaybeJSONValue, MaybeJSONValue];
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
toString(): string;
|
|
44
|
+
/**
|
|
45
|
+
* Return _true_ if this pointer points to a child of _pointer_.
|
|
46
|
+
*/
|
|
47
|
+
isRelativeTo(pointer: JSONPointer): boolean;
|
|
48
|
+
protected parse(pointer: string): string[];
|
|
49
|
+
protected getItem(val: JSONValue, token: string, idx: number): JSONValue;
|
|
50
|
+
private _join;
|
|
51
|
+
/**
|
|
52
|
+
* Join this pointer with _tokens_.
|
|
53
|
+
*
|
|
54
|
+
* @param tokens - JSON Pointer strings, possibly without leading slashes.
|
|
55
|
+
* If a token or "part" does have a leading slash, the previous pointer is
|
|
56
|
+
* ignored and a new `JSONPointer` is created, then processing of the
|
|
57
|
+
* remaining tokens continues.
|
|
58
|
+
*
|
|
59
|
+
* @returns A new JSON Pointer that is the concatenation of all tokens or
|
|
60
|
+
* "parts".
|
|
61
|
+
*/
|
|
62
|
+
join(...tokens: string[]): JSONPointer;
|
|
63
|
+
/**
|
|
64
|
+
* Return _true_ if this pointer can be resolved against _value_.
|
|
65
|
+
*
|
|
66
|
+
* Note that `JSONPointer.resolve()` can return legitimate falsy values
|
|
67
|
+
* that form part of the target JSON document. This method will return
|
|
68
|
+
* `true` if a falsy value is found.
|
|
69
|
+
*/
|
|
70
|
+
exists(value: JSONValue): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Return this pointer's parent as a new `JSONPointer`.
|
|
73
|
+
*
|
|
74
|
+
* If this pointer points to the document root, _this_ is returned.
|
|
75
|
+
*/
|
|
76
|
+
parent(): JSONPointer;
|
|
77
|
+
to(rel: string | RelativeJSONPointer): JSONPointer;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A relative JSON Pointer.
|
|
81
|
+
*
|
|
82
|
+
* See https://datatracker.ietf.org/doc/html/draft-hha-relative-json-pointer
|
|
83
|
+
*/
|
|
84
|
+
export declare class RelativeJSONPointer {
|
|
85
|
+
readonly origin: number;
|
|
86
|
+
readonly index: number;
|
|
87
|
+
readonly pointer: string | JSONPointer;
|
|
88
|
+
/**
|
|
89
|
+
*
|
|
90
|
+
* @param rel -
|
|
91
|
+
*/
|
|
92
|
+
constructor(rel: string);
|
|
93
|
+
/**
|
|
94
|
+
*
|
|
95
|
+
* @returns
|
|
96
|
+
*/
|
|
97
|
+
toString(): string;
|
|
98
|
+
/**
|
|
99
|
+
*
|
|
100
|
+
* @param pointer -
|
|
101
|
+
*/
|
|
102
|
+
to(pointer: string | JSONPointer): JSONPointer;
|
|
103
|
+
protected parse(rel: string): [number, number, string | JSONPointer];
|
|
104
|
+
protected parseInt(s: string): number;
|
|
105
|
+
protected isIntLike(value: string | number | undefined): boolean;
|
|
106
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common types and type predicates.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* A JSON-like value.
|
|
6
|
+
*/
|
|
7
|
+
export type JSONValue = string | number | null | undefined | boolean | JSONValue[] | {
|
|
8
|
+
[key: string]: JSONValue;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A type predicate for the Array object.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isArray(value: unknown): value is unknown[];
|
|
14
|
+
/**
|
|
15
|
+
* A type predicate for object.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isObject(value: unknown): value is object;
|
|
18
|
+
/**
|
|
19
|
+
* A type predicate for a string primitive.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isString(value: unknown): value is string;
|
|
22
|
+
/**
|
|
23
|
+
* A type predicate for a number primitive.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isNumber(value: unknown): value is number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-p3",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"author": "James Prior",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "JSONPath, JSON Pointer and JSON Patch",
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"test": "jest",
|
|
17
|
-
"build:types": "tsc --emitDeclarationOnly",
|
|
17
|
+
"build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly",
|
|
18
18
|
"build:js": "rollup -c",
|
|
19
19
|
"build": "npm run build:types && npm run build:js",
|
|
20
|
-
"type-check": "tsc --noEmit",
|
|
20
|
+
"type-check": "tsc -p tsconfig.build.json --noEmit",
|
|
21
21
|
"coverage": "jest --collectCoverage",
|
|
22
22
|
"clean": "rm -rf ./lib ./dist ./coverage ./docs/docs/api",
|
|
23
23
|
"lint": "eslint src tests --ext .js,.jsx,.ts,.tsx"
|