UNPKG

1.18 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.parseJsonPointer = exports.joinJsonPointer = exports.buildJsonPointer = void 0;
11function buildJsonPointer(fragments) {
12 return ('/' +
13 fragments
14 .map((f) => {
15 return f.replace(/~/g, '~0').replace(/\//g, '~1');
16 })
17 .join('/'));
18}
19exports.buildJsonPointer = buildJsonPointer;
20function joinJsonPointer(root, ...others) {
21 if (root == '/') {
22 return buildJsonPointer(others);
23 }
24 return (root + buildJsonPointer(others));
25}
26exports.joinJsonPointer = joinJsonPointer;
27function 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}
39exports.parseJsonPointer = parseJsonPointer;