jsonpointerx
Version:
fast jsonpointer (rfc6901) implementation
88 lines (87 loc) • 3.18 kB
TypeScript
export interface JsonPointerOpts {
noCompile?: boolean;
blacklist?: string[];
}
export declare class JsonPointer {
private static opts;
private readonly _segments;
get segments(): string[];
get root(): boolean;
private fnGet;
/**
* Creates an instance of JsonPointer.
* @param [segments] - The path segments of the json-pointer / The decoded json-pointer
* @param [noCompile] - disable compiling (using 'new Function')
*/
constructor(segments?: string | string[], noCompile?: boolean);
/**
* Get a value from a referenced location within an object
*
* @param input - The object to be read from
* @returns The value from the referenced location or undefined
*/
get(input: any): any;
/**
* fallback if compilation (using 'new Function') is disabled
*
* @param input - The object to be read from
* @returns The value from the referenced location or undefined
*/
notCompiledGet(input: any): any;
/**
* Set a value to the referenced location within an object
*
* @param obj - To object to be written in
* @param [value] - The value to be written to the referenced location
* @returns returns 'value' if pointer.length === 1 or 'input' otherwise
*
* throws if 'input' is not an object
* throws if 'set' is called for a root JSON pointer
* throws on invalid array index references
* throws if one of the ancestors is a scalar (js engine): Cannot create propery 'foo' on 'baz'
*/
set(input: any, value?: any): any;
concat(p: JsonPointer): JsonPointer;
concatSegment(segment: string | string[]): JsonPointer;
concatPointer(pointer: string): JsonPointer;
toString(): string;
toURIFragmentIdentifier(): string;
private compileFunctions;
/**
* Instantiate a new 'JsonPointer' from encoded json-pointer
*
* @static
* @param pointer - The encoded json-pointer
* @param {boolean} [decodeOnly] - only decode and do not compile (using 'new Function')
* @returns {JsonPointer}
*/
static compile(pointer: string, decodeOnly?: boolean): JsonPointer;
/**
* Get a value from a referenced location within an object
*
* @static
* @param obj - The object to be read from
* @param {string} pointer - The encoded json-pointer
* @returns The value from the referenced location or undefined
*/
static get(obj: any, pointer: string): any;
/**
* Set a value to the referenced location within an object
*
* @static
* @param obj - To object to be written in
* @param pointer - The encoded json-pointer
* @param [value] - The value to be written to the referenced location
* @returns returns 'value' if pointer.length === 1 or 'input' otherwise
*/
static set(obj: any, pointer: string, value?: any): any;
/**
* set global options
*
* @static
* @param {JsonPointerOpts} opts
*/
static options(opts?: JsonPointerOpts): JsonPointerOpts | undefined;
private static fromJpStringReplace;
private static toJpStringReplace;
}