source: node_modules/@swagger-api/apidom-json-pointer/README.md@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[d24f17c]1# @swagger-api/apidom-json-pointer
2
3`apidom-json-pointer` is a package that evaluates [JSON Pointer](https://datatracker.ietf.org/doc/html/rfc6901) against ApiDOM.
4
5## Installation
6
7You can install this package via [npm CLI](https://docs.npmjs.com/cli) by running the following command:
8
9```sh
10 $ npm install @swagger-api/apidom-json-pointer
11```
12## Evaluating
13
14```js
15import { ObjectElement } from '@swagger-api/apidom-core';
16import { evaluate } from '@swagger-api/apidom-json-pointer';
17
18const apidom = new ObjectElement({ a: { b: 'c' } });
19const result = evaluate('/a/b', apidom);
20// => StringElement('c')
21```
22
23## Parsing
24
25Parses JSON Pointer into list of tokens.
26
27```js
28import { parse } from '@swagger-api/apidom-json-pointer';
29
30const tokens = parse('/a/b'); // => ['a', 'b']
31```
32
33## Compiling
34
35Compiles list of tokens into JSON Pointer.
36
37```js
38import { compile } from '@swagger-api/apidom-json-pointer';
39
40const jsonPointer = compile(['a', 'b']); // => '/a/b'
41```
42
43## Escaping
44
45Escapes/unescapes tokens of JSON Pointer.
46
47```js
48import { escape, unescape } from '@swagger-api/apidom-json-pointer';
49
50escape('~a/'); // => '~0a~1'
51unescape('~0a~1'); // => '~a/'
52```
53
54## Transforming URI to JSON Pointer
55
56Handles case of [URI Fragment Identifier Representation](https://datatracker.ietf.org/doc/html/rfc6901#section-6).
57
58```js
59import { uriToPointer } from '@swagger-api/apidom-json-pointer';
60
61uriToPointer('https://example.com/path/#/a/b'); // => '/a/b'
62```
63
64## Invalid JSON Pointers
65
66If invalid JSON Pointer is supplied to `parse` or `evaluate` functions, `InvalidJsonPointerError`
67is thrown.
68
69```js
70import { InvalidJsonPointerError } from '@swagger-api/apidom-json-pointer';
71```
72
73If valid JSON Pointer is supplied to `evaluate` function and the pointer cannot be evaluated against
74ApiDOM fragment, `EvaluationJsonPointerError` is thrown.
75
76```js
77import { EvaluationJsonPointerError } from '@swagger-api/apidom-json-pointer';
78```
Note: See TracBrowser for help on using the repository browser.