@crikey/json-private-pointer v0.0.2
@crikey/json-private-pointer
Functions for handling JSON pointers rfc6901 and relative-json-pointer, with an additional extension for marking path segments as "public" or "private".
See @crikey/json-private-pointer for full documentation.
API
Types
Contains types used to represent JSON pointers and segments
Guards
Contains typescript guards for identifying type information.
is_pointerReturns true if value is aPointeris_absoluteReturns true if value is anAbsolutePointeris_relativeReturns true if value is aRelativePointer
Error classes
Classes used when throwing errors
PointerDecodingErrorError class thrown for pointer decoding errorsPointerEncodingErrorError class thrown for pointer encoding errors
Creation
Functions used for creating paths from their constituent parts
pointerCreate aPointerfrom a series of decoded segmentsabsoluteCreate anAbsolutePointerfrom a series of decoded segmentsrelativeCreate aRelativePointerfrom arelativenumber and a series of decoded segmentspointer_encodedCreate aPointerfrom an optionalrelativenumber and a series of encoded segmentsabsolute_encodedCreate anAbsolutePointerfrom a series of encoded segmentsrelative_encodedCreate aRelativePointerfrom arelativenumber and a series of encoded segments
Joining
Combining pointer components and segments
join_pointerJoin twoPointers togetherjoin_segmentsAppend decoded segments onto an existingPointerjoin_encoded_segmentsAppend encoded segments onto an existingPointer
Encoding
Encode and decode path segments
segment_encodeEncode a given string segmentsegment_decodeDecode a given string segment
Splitting
Split paths into their constituent components/segments
splitSplit aPointerinto its constituent parts, decoding each segmentsplit_absoluteSplit aAbsolutePointerinto its constituent parts, decoding each segmentsplit_relativeSplit aRelativePointerinto its constituent parts, decoding each segmentsplit_encodedSplit aPointerinto its constituent parts, leaving segments encodedsplit_encoded_absoluteSplit aAbsolutePointerinto its constituent parts, leaving segments encodedsplit_encoded_relativeSplit aRelativePointerinto its constituent parts, leaving segments encoded
Installation
# pnpm
$ pnpm add @crikey/json-private-pointer
# npm
$ npm add @crikey/json-private-pointer
# yarn
$ yarn add @crikey/json-private-pointerExample Usage
Guards
console.log(is_pointer('xyz')); // false
console.log(is_pointer('/xyz')); // true
console.log(is_pointer('123/xyz')); // true
console.log(is_absolute('123/xyz')); // false
console.log(is_relative('123/xyz')); // trueCreating
console.log(pointer('x',[true, 'y'], [false, 'z'])); // '/x/~3y/z'
console.log(pointer('~/')); // '/~0~1'
console.log(pointer(undefined,'x','y','z')); // '/x/y/z'
console.log(pointer(123,'x','y','z')); // '123/x/y/z'
console.log(relative(123,'x','y','z')); // '123/x/y/z'Joining
console.log(join_pointer('/a/b/c', '/x/y/z')); // '/x/y/z'
console.log(join_pointer('/a/b/c', '1/x/y/z')); // '/a/b/x/y/z'
console.log(join_segments('/a/b/c', 'x', [true, 'y'], 'z')); // '/a/b/c/x/~3y/z'
console.log(join_segments('/a/b/c', '~')); // '/a/b/c/~0'Splitting
console.log(split('/a/~3b/c')); // { segments: [[false, 'a'], [true, 'b'], [false, 'c']] }
console.log(split('123/a/~3b/c')); // { relative: 123, segments: [false, 'a'], [true, 'b'], [false, 'c'] }