1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | exports.parseJsonPointer = exports.joinJsonPointer = exports.buildJsonPointer = void 0;
|
11 | function buildJsonPointer(fragments) {
|
12 | return ('/' +
|
13 | fragments
|
14 | .map((f) => {
|
15 | return f.replace(/~/g, '~0').replace(/\//g, '~1');
|
16 | })
|
17 | .join('/'));
|
18 | }
|
19 | exports.buildJsonPointer = buildJsonPointer;
|
20 | function joinJsonPointer(root, ...others) {
|
21 | if (root == '/') {
|
22 | return buildJsonPointer(others);
|
23 | }
|
24 | return (root + buildJsonPointer(others));
|
25 | }
|
26 | exports.joinJsonPointer = joinJsonPointer;
|
27 | function parseJsonPointer(pointer) {
|
28 | if (pointer === '') {
|
29 | return [];
|
30 | }
|
31 | if (pointer.charAt(0) !== '/') {
|
32 | throw new Error('Relative pointer: ' + pointer);
|
33 | }
|
34 | return pointer
|
35 | .substring(1)
|
36 | .split(/\//)
|
37 | .map((str) => str.replace(/~1/g, '/').replace(/~0/g, '~'));
|
38 | }
|
39 | exports.parseJsonPointer = parseJsonPointer;
|