@swagger-api/apidom-json-pointer-relative
apidom-json-pointer-relative
is a package that evaluates Relative JSON Pointer against ApiDOM.
Installation
You can install this package via npm CLI by running the following command:
$ npm install @swagger-api/apidom-json-pointer-relative
Evaluating
import { ObjectElement } from '@swagger-api/apidom-core';
import { evaluate } from '@swagger-api/apidom-json-pointer-relative';
const root = new ObjectElement({ a: { b: 'c' } });
const current = root.get('a').get('b');
const result = evaluate('0#', current, root);
Parsing
Parses Relative JSON Pointer into AST (Abstract Syntax Tree).
import { parse } from '@swagger-api/apidom-json-pointer-relative';
const tokens = parse('2/foo/0');
Compiling
Compiles AST into Relative JSON Pointer.
import { compile } from '@swagger-api/apidom-json-pointer-relative';
const relativeJsonPointer = compile({
nonNegativeIntegerPrefix: 2,
indexManipulation: undefined,
jsonPointerTokens: ['highly', 'nested', 'objects'],
hashCharacter: false,
});
Invalid Relative JSON Pointers
If invalid Relative JSON Pointer is supplied to parse
or evaluate
functions, InvalidRelativeJsonPointerError
is thrown.
import { InvalidRelativeJsonPointerError } from '@swagger-api/apidom-json-pointer-relative';
If valid JSON Pointer is supplied to evaluate
function and the relative pointer cannot be evaluated against
ApiDOM fragment, EvaluationRelativeJsonPointerError
is thrown.
import { EvaluationRelativeJsonPointerError } from '@swagger-api/apidom-json-pointer-relative';