UNPKG

2.18 kBTypeScriptView Raw
1/**
2Unescape token part of a JSON Pointer string
3
4`token` should *not* contain any '/' characters.
5
6> Evaluation of each reference token begins by decoding any escaped
7> character sequence. This is performed by first transforming any
8> occurrence of the sequence '~1' to '/', and then transforming any
9> occurrence of the sequence '~0' to '~'. By performing the
10> substitutions in this order, an implementation avoids the error of
11> turning '~01' first into '~1' and then into '/', which would be
12> incorrect (the string '~01' correctly becomes '~1' after
13> transformation).
14
15Here's my take:
16
17~1 is unescaped with higher priority than ~0 because it is a lower-order escape character.
18I say "lower order" because '/' needs escaping due to the JSON Pointer serialization technique.
19Whereas, '~' is escaped because escaping '/' uses the '~' character.
20*/
21export declare function unescapeToken(token: string): string;
22/** Escape token part of a JSON Pointer string
23
24> '~' needs to be encoded as '~0' and '/'
25> needs to be encoded as '~1' when these characters appear in a
26> reference token.
27
28This is the exact inverse of `unescapeToken()`, so the reverse replacements must take place in reverse order.
29*/
30export declare function escapeToken(token: string): string;
31export interface PointerEvaluation {
32 parent: any;
33 key: string;
34 value: any;
35}
36/**
37JSON Pointer representation
38*/
39export declare class Pointer {
40 tokens: string[];
41 constructor(tokens?: string[]);
42 /**
43 `path` *must* be a properly escaped string.
44 */
45 static fromJSON(path: string): Pointer;
46 toString(): string;
47 /**
48 Returns an object with 'parent', 'key', and 'value' properties.
49 In the special case that this Pointer's path == "",
50 this object will be {parent: null, key: '', value: object}.
51 Otherwise, parent and key will have the property such that parent[key] == value.
52 */
53 evaluate(object: any): PointerEvaluation;
54 get(object: any): any;
55 set(object: any, value: any): void;
56 push(token: string): void;
57 /**
58 `token` should be a String. It'll be coerced to one anyway.
59
60 immutable (shallowly)
61 */
62 add(token: string): Pointer;
63}