Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-ptr

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-ptr - npm Package Compare versions

Comparing version 3.1.1-symbols.0e6db58 to 3.1.2-main.1988f05

403

dist/cjs/index.js

@@ -42,5 +42,2 @@ 'use strict';

}
else if (typeof segments[i] === 'symbol') {
res[i] = `Symbol(${segments[i].description})`;
}
else {

@@ -74,5 +71,2 @@ res[i] = segments[i];

}
else if (typeof segments[i] === 'symbol') {
res[i] = `Symbol(${segments[i].description})`;
}
else {

@@ -145,3 +139,3 @@ res[i] = segments[i];

}
first = first.substring(0, first.length - 1);
first = first.substr(0, first.length - 1);
}

@@ -162,4 +156,2 @@ let i = -1;

return idx;
if (typeof idx === 'symbol')
return idx;
const len = idx.length;

@@ -185,29 +177,13 @@ if (!len)

if (path.length === 0) {
return (_, it) => it;
return (it) => it;
}
let i = -1;
const len = path.length;
while (++i < len) {
if (typeof path[i] === 'symbol') {
body =
body +
'\n\t&& it !== null && typeof((it = it[path[' +
i +
"]])) !== 'undefined'";
}
else {
const p = path[i];
body =
body +
"\n\t&& it !== null && typeof((it = it['" +
replace(replace(p + '', '\\', '\\\\'), "'", "\\'") +
"'])) !== 'undefined'";
}
}
body = path.reduce((body, _, i) => {
return (body +
"\n\t&& it !== null && typeof((it = it['" +
replace(replace(path[i] + '', '\\', '\\\\'), "'", "\\'") +
"'])) !== 'undefined'");
}, "if (typeof(it) !== 'undefined'");
body = body + ') {\n\treturn it;\n }';
// eslint-disable-next-line no-new-func
const generated = new Function('path', 'it', body);
// sometimes, it's useful to visualize the generated getters.
// console.log(`${encodePointer(path)} = ${generated.toString()}`);
return generated;
return new Function('it', body);
}

@@ -225,10 +201,10 @@ function setValueAtPath(target, val, path, force = false) {

const end = path.length - 1;
let step;
let cursor = -1;
let rem;
let p;
while (++cursor < len) {
const step = path[cursor];
if (typeof step !== 'string' &&
typeof step !== 'number' &&
typeof step !== 'symbol') {
throw new TypeError('PathSegments must be a string, number, or symbol.');
step = path[cursor];
if (typeof step !== 'string' && typeof step !== 'number') {
throw new TypeError('PathSegments must be a string or a number.');
}

@@ -249,4 +225,4 @@ if (

}
const p = toArrayIndexReference(it, step);
if (typeof p === 'symbol') {
p = toArrayIndexReference(it, step);
if (it.length > p) {
if (cursor === end) {

@@ -259,21 +235,11 @@ rem = it[p];

}
else {
if (it.length > p) {
if (cursor === end) {
rem = it[p];
it[p] = val;
break;
}
it = it[p];
else if (cursor === end && p === it.length) {
if (force) {
it.push(val);
return undefined;
}
else if (cursor === end && p === it.length) {
if (force) {
it.push(val);
return undefined;
}
}
else if (force) {
it = it[p] = cursor === end ? val : {};
}
}
else if (force) {
it = it[p] = cursor === end ? val : {};
}
}

@@ -320,6 +286,8 @@ else {

const end = path.length - 1;
let step;
let cursor = -1;
let rem;
let p;
while (++cursor < len) {
const step = path[cursor];
step = path[cursor];
if (typeof step !== 'string' && typeof step !== 'number') {

@@ -334,21 +302,11 @@ throw new TypeError('PathSegments must be a string or a number.');

if (Array.isArray(it)) {
const p = toArrayIndexReference(it, step);
if (typeof p === 'symbol') {
if (cursor === end) {
rem = it[p];
delete it[p];
break;
}
it = it[p];
p = toArrayIndexReference(it, step);
if (p >= it.length)
return undefined;
if (cursor === end) {
rem = it[p];
delete it[p];
break;
}
else {
if (p >= it.length)
return undefined;
if (cursor === end) {
rem = it[p];
delete it[p];
break;
}
it = it[p];
}
it = it[p];
}

@@ -396,3 +354,3 @@ else {

/** @hidden */
function descendingVisit(target, visitor, includeSymbols = false) {
function descendingVisit(target, visitor, encoder) {
const distinctObjects = new Map();

@@ -402,10 +360,7 @@ const q = [{ obj: target, path: [] }];

const { obj, path } = q.shift();
visitor(new JsonPointer(path), obj);
visitor(encoder(path), obj);
if (shouldDescend(obj)) {
distinctObjects.set(obj, new JsonPointer(path));
distinctObjects.set(obj, new JsonPointer(encodeUriFragmentIdentifier(path)));
if (!Array.isArray(obj)) {
let keys = Object.keys(obj);
if (includeSymbols) {
keys = keys.concat(Object.getOwnPropertySymbols(obj));
}
const keys = Object.keys(obj);
const len = keys.length;

@@ -431,10 +386,10 @@ let i = -1;

// handleArray
let i = -1;
let j = -1;
const len = obj.length;
while (++i < len) {
const it = obj[i];
while (++j < len) {
const it = obj[j];
if (isObject(it) && distinctObjects.has(it)) {
q.push({
obj: new JsonReference(distinctObjects.get(it)),
path: path.concat([i]),
path: path.concat([j + '']),
});

@@ -445,3 +400,3 @@ }

obj: it,
path: path.concat([i]),
path: path.concat([j + '']),
});

@@ -455,132 +410,8 @@ }

/** @hidden */
const $get = Symbol('$get');
const $ptr = Symbol('pointer');
/** @hidden */
const $frg = Symbol('$frg');
const $frg = Symbol('fragmentId');
/** @hidden */
const $symbols = Symbol('$symbols');
const $get = Symbol('getter');
/**
* Symbol used to cache pre-compiled getters on target objects used with static
* pointer methods.
* @hidden
*/
const $cache = Symbol('$cache');
/**
* Enables pointer caching for the specified object. Pointer caching can save
* processing cycles when frequently executing pointer operations against an
* object, using transient JsonPointer instances, such as those used by static
* methods like [[JsonPointer.get]].
*
* The cache gets cleaned up with the target instance, when the target goes out
* of scope.
* @param target the object on which pointer caching will be enabled.
* @returns the target object
*/
const enablePointerCaching = (target) => {
const caching = target;
let cache = caching[$cache];
if (!cache) {
cache = new Map();
caching[$cache] = cache;
}
return target;
};
const disablePointerCaching = (target) => {
const caching = target;
if (caching[$cache]) {
delete caching[$cache];
}
return target;
};
function countSymbols(path) {
let symbols = path[$symbols];
if (typeof symbols === 'undefined') {
symbols = [];
const certainlyPath = path;
let i = -1;
const len = certainlyPath.length;
while (++i < len) {
if (typeof certainlyPath[i] === 'symbol') {
symbols.push(i);
}
}
path[$symbols] = symbols;
}
return symbols;
}
function resolveGetterOrCompile(ptr, target, getter) {
const { pointer, path } = ptr;
const symbols = countSymbols(path);
const cache = target[$cache];
if (cache) {
// the object has a pointer cache.
let records = cache.get(pointer);
if (!records) {
// the object has not seen this pointer
getter = getter || compilePointerDereference(path);
records = [[symbols, path, getter]];
cache.set(pointer, records);
return getter;
}
// There should only be a few, because it requires symbols at the same path
// segment, with the same name, but different symbol scope. Possible but
// unlikely.
for (const [s, p, g] of records) {
if (s.length == symbols.length) {
// somewhat unroll the loops
switch (s.length) {
case 0:
return g;
case 1:
if (s[0] === symbols[0] && p[s[0]] === path[symbols[0]])
return g;
break;
case 2:
if (s[0] === symbols[0] &&
p[s[0]] === path[symbols[0]] &&
s[1] === symbols[1] &&
p[s[1]] === path[symbols[1]])
return g;
break;
case 3:
if (s[0] === symbols[0] &&
p[s[0]] === path[symbols[0]] &&
s[1] === symbols[1] &&
p[s[1]] === path[symbols[1]] &&
s[2] === symbols[2] &&
p[s[2]] === path[symbols[2]])
return g;
break;
default:
// ok, more than 3, so loop
if (s[0] === symbols[0] &&
p[s[0]] === path[symbols[0]] &&
s[1] === symbols[1] &&
p[s[1]] === path[symbols[1]] &&
s[2] === symbols[2] &&
p[s[2]] === path[symbols[2]] &&
s[3] === symbols[3] &&
p[s[3]] === path[symbols[3]]) {
// loop over the remainder...
let seemsEqual = true;
let j = 3;
const len = s.length;
while (seemsEqual && ++j < len) {
seemsEqual =
s[j] === symbols[j] && p[s[j]] === path[symbols[j]];
}
if (seemsEqual)
return g;
}
break;
}
}
}
// We get here if there isn't a match in the cache.
getter = getter || compilePointerDereference(path);
records.push([symbols, path, getter]);
return getter;
}
return getter || compilePointerDereference(path);
}
/**
* Represents a JSON Pointer, capable of getting and setting the value on target

@@ -695,16 +526,6 @@ * objects at the pointer's location.

* Creates a new instance.
*
* If [[ptr]] is another [[JsonPointer]] then consider this a copy constructor.
* @param ptr a string representation of a JSON Pointer, a decoded array of path segments, or another JsonPointer.
* @param ptr a string representation of a JSON Pointer, or a decoded array of path segments.
*/
constructor(ptr) {
if (ptr instanceof JsonPointer) {
// copy construct...
this.path = ptr.path;
this.pointer = ptr.pointer;
this[$get] = ptr[$get];
return;
}
const path = (this.path = decodePtrInit(ptr));
this.pointer = encodePointer(path);
this.path = decodePtrInit(ptr);
}

@@ -865,41 +686,27 @@ /**

* @param visitor a callback function invoked for each unique pointer location in the object graph
* @param includeSymbols indicates whether the results should include paths across symbols (these don't round-trip to legitimate JSON Pointers)
* @param fragmentId indicates whether the visitor should receive fragment identifiers or regular pointers
*/
static visit(target, visitor, includeSymbols = false) {
descendingVisit(target, visitor, includeSymbols);
static visit(target, visitor, fragmentId = false) {
descendingVisit(target, visitor, fragmentId ? encodeUriFragmentIdentifier : encodePointer);
}
/**
* Evaluates the target's object graph, returning a [[PointerPair]] for each location in the graph.
* @param target the target of the operation
* @param includeSymbols indicates whether the results should include paths across symbols (these don't round-trip to legitimate JSON Pointers)
*/
static listPairs(target, includeSymbols = false) {
const res = [];
descendingVisit(target, (pointer, value) => {
res.push([pointer, value]);
}, includeSymbols);
return res;
}
/**
* Evaluates the target's object graph, returning a [[JsonStringPointerListItem]] for each location in the graph.
* @param target the target of the operation
* @param includeSymbols indicates whether the results should include paths across symbols (these don't round-trip to legitimate JSON Pointers)
*/
static listPointers(target, includeSymbols = false) {
static listPointers(target) {
const res = [];
descendingVisit(target, (pointer, value) => {
res.push({ pointer: pointer.pointer, value });
}, includeSymbols);
res.push({ pointer, value });
}, encodePointer);
return res;
}
/**
* Evaluates the target's object graph, returning a [[JsonStringPointerListItem]] for each location in the graph.
* Evaluates the target's object graph, returning a [[UriFragmentIdentifierPointerListItem]] for each location in the graph.
* @param target the target of the operation
* @param includeSymbols indicates whether the results should include paths across symbols (these don't round-trip to legitimate JSON Pointers)
*/
static listFragmentIds(target, includeSymbols = false) {
static listFragmentIds(target) {
const res = [];
descendingVisit(target, (pointer, value) => {
res.push({ fragmentId: pointer.uriFragmentIdentifier, value });
}, includeSymbols);
descendingVisit(target, (fragmentId, value) => {
res.push({ fragmentId, value });
}, encodeUriFragmentIdentifier);
return res;

@@ -910,20 +717,11 @@ }

* @param target the target of the operation
* @param includeSymbols indicates whether the results should include paths across symbols (these don't round-trip to legitimate JSON Pointers)
* @param fragmentId indicates whether the results are populated with fragment identifiers rather than regular pointers
*/
static flatten(target, includeSymbols = false) {
static flatten(target, fragmentId = false) {
const res = {};
descendingVisit(target, (pointer, value) => {
res[pointer.pointer] = value;
}, includeSymbols);
descendingVisit(target, (p, v) => {
res[p] = v;
}, fragmentId ? encodeUriFragmentIdentifier : encodePointer);
return res;
}
static pointersWithSymbol(target, sym) {
const res = [];
descendingVisit(target, (pointer) => {
if (~pointer.path.indexOf(sym)) {
res.push(pointer);
}
}, true);
return res;
}
/**

@@ -933,10 +731,6 @@ * Evaluates the target's object graph, returning a Map&lt;Pointer,unknown> populated with pointers and the corresponding values form the graph.

* @param fragmentId indicates whether the results are populated with fragment identifiers rather than regular pointers
* @param includeSymbols indicates whether the results should include paths across symbols (these don't round-trip to legitimate JSON Pointers)
*/
static map(target, fragmentId = false, includeSymbols = false) {
static map(target, fragmentId = false) {
const res = new Map();
const encoder = fragmentId ? encodeUriFragmentIdentifier : encodePointer;
descendingVisit(target, (p, v) => {
res.set(encoder(p.path), v);
}, includeSymbols);
descendingVisit(target, res.set.bind(res), fragmentId ? encodeUriFragmentIdentifier : encodePointer);
return res;

@@ -950,5 +744,5 @@ }

if (!this[$get]) {
this[$get] = resolveGetterOrCompile(this, target);
this[$get] = compilePointerDereference(this.path);
}
return this[$get](this.path, target);
return this[$get](target);
}

@@ -1047,2 +841,11 @@ /**

/**
* This pointer's JSON Pointer encoded string representation.
*/
get pointer() {
if (this[$ptr] === undefined) {
this[$ptr] = encodePointer(this.path);
}
return this[$ptr];
}
/**
* This pointer's URI fragment identifier encoded string representation.

@@ -1063,42 +866,2 @@ */

}
/**
* Re-export of [[JsonPointer.create]] to support classic API
*/
const create = JsonPointer.create;
/**
* Re-export of [[JsonPointer.get]] to support classic API
*/
const get = JsonPointer.get;
/**
* Re-export of [[JsonPointer.set]] to support classic API
*/
const set = JsonPointer.set;
/**
* Re-export of [[JsonPointer.unset]] to support classic API
*/
const unset = JsonPointer.unset;
/**
* Re-export of [[JsonPointer.decode]] to support classic API
*/
const decode = JsonPointer.decode;
/**
* Re-export of [[JsonPointer.visit]] to support classic API
*/
const visit = JsonPointer.visit;
/**
* Re-export of [[JsonPointer.listPointers]] to support classic API
*/
const listPointers = JsonPointer.listPointers;
/**
* Re-export of [[JsonPointer.listFragmentIds]] to support classic API
*/
const listFragmentIds = JsonPointer.listFragmentIds;
/**
* Re-export of [[JsonPointer.flatten]] to support classic API
*/
const flatten = JsonPointer.flatten;
/**
* Re-export of [[JsonPointer.map]] to support classic API
*/
const map = JsonPointer.map;
/** @hidden */

@@ -1157,4 +920,2 @@ const $pointer = Symbol('pointer');

exports.compilePointerDereference = compilePointerDereference;
exports.create = create;
exports.decode = decode;
exports.decodeFragmentSegments = decodeFragmentSegments;

@@ -1166,4 +927,2 @@ exports.decodePointer = decodePointer;

exports.decodeUriFragmentIdentifier = decodeUriFragmentIdentifier;
exports.disablePointerCaching = disablePointerCaching;
exports.enablePointerCaching = enablePointerCaching;
exports.encodeFragmentSegments = encodeFragmentSegments;

@@ -1173,16 +932,8 @@ exports.encodePointer = encodePointer;

exports.encodeUriFragmentIdentifier = encodeUriFragmentIdentifier;
exports.flatten = flatten;
exports.get = get;
exports.listFragmentIds = listFragmentIds;
exports.listPointers = listPointers;
exports.looksLikeFragment = looksLikeFragment;
exports.map = map;
exports.pickDecoder = pickDecoder;
exports.replace = replace;
exports.set = set;
exports.setValueAtPath = setValueAtPath;
exports.toArrayIndexReference = toArrayIndexReference;
exports.unset = unset;
exports.unsetValueAtPath = unsetValueAtPath;
exports.visit = visit;
//# sourceMappingURL=index.js.map

@@ -38,5 +38,2 @@ function replace(source, find, repl) {

}
else if (typeof segments[i] === 'symbol') {
res[i] = `Symbol(${segments[i].description})`;
}
else {

@@ -70,5 +67,2 @@ res[i] = segments[i];

}
else if (typeof segments[i] === 'symbol') {
res[i] = `Symbol(${segments[i].description})`;
}
else {

@@ -141,3 +135,3 @@ res[i] = segments[i];

}
first = first.substring(0, first.length - 1);
first = first.substr(0, first.length - 1);
}

@@ -158,4 +152,2 @@ let i = -1;

return idx;
if (typeof idx === 'symbol')
return idx;
const len = idx.length;

@@ -181,29 +173,13 @@ if (!len)

if (path.length === 0) {
return (_, it) => it;
return (it) => it;
}
let i = -1;
const len = path.length;
while (++i < len) {
if (typeof path[i] === 'symbol') {
body =
body +
'\n\t&& it !== null && typeof((it = it[path[' +
i +
"]])) !== 'undefined'";
}
else {
const p = path[i];
body =
body +
"\n\t&& it !== null && typeof((it = it['" +
replace(replace(p + '', '\\', '\\\\'), "'", "\\'") +
"'])) !== 'undefined'";
}
}
body = path.reduce((body, _, i) => {
return (body +
"\n\t&& it !== null && typeof((it = it['" +
replace(replace(path[i] + '', '\\', '\\\\'), "'", "\\'") +
"'])) !== 'undefined'");
}, "if (typeof(it) !== 'undefined'");
body = body + ') {\n\treturn it;\n }';
// eslint-disable-next-line no-new-func
const generated = new Function('path', 'it', body);
// sometimes, it's useful to visualize the generated getters.
// console.log(`${encodePointer(path)} = ${generated.toString()}`);
return generated;
return new Function('it', body);
}

@@ -221,10 +197,10 @@ function setValueAtPath(target, val, path, force = false) {

const end = path.length - 1;
let step;
let cursor = -1;
let rem;
let p;
while (++cursor < len) {
const step = path[cursor];
if (typeof step !== 'string' &&
typeof step !== 'number' &&
typeof step !== 'symbol') {
throw new TypeError('PathSegments must be a string, number, or symbol.');
step = path[cursor];
if (typeof step !== 'string' && typeof step !== 'number') {
throw new TypeError('PathSegments must be a string or a number.');
}

@@ -245,4 +221,4 @@ if (

}
const p = toArrayIndexReference(it, step);
if (typeof p === 'symbol') {
p = toArrayIndexReference(it, step);
if (it.length > p) {
if (cursor === end) {

@@ -255,21 +231,11 @@ rem = it[p];

}
else {
if (it.length > p) {
if (cursor === end) {
rem = it[p];
it[p] = val;
break;
}
it = it[p];
else if (cursor === end && p === it.length) {
if (force) {
it.push(val);
return undefined;
}
else if (cursor === end && p === it.length) {
if (force) {
it.push(val);
return undefined;
}
}
else if (force) {
it = it[p] = cursor === end ? val : {};
}
}
else if (force) {
it = it[p] = cursor === end ? val : {};
}
}

@@ -316,6 +282,8 @@ else {

const end = path.length - 1;
let step;
let cursor = -1;
let rem;
let p;
while (++cursor < len) {
const step = path[cursor];
step = path[cursor];
if (typeof step !== 'string' && typeof step !== 'number') {

@@ -330,21 +298,11 @@ throw new TypeError('PathSegments must be a string or a number.');

if (Array.isArray(it)) {
const p = toArrayIndexReference(it, step);
if (typeof p === 'symbol') {
if (cursor === end) {
rem = it[p];
delete it[p];
break;
}
it = it[p];
p = toArrayIndexReference(it, step);
if (p >= it.length)
return undefined;
if (cursor === end) {
rem = it[p];
delete it[p];
break;
}
else {
if (p >= it.length)
return undefined;
if (cursor === end) {
rem = it[p];
delete it[p];
break;
}
it = it[p];
}
it = it[p];
}

@@ -392,3 +350,3 @@ else {

/** @hidden */
function descendingVisit(target, visitor, includeSymbols = false) {
function descendingVisit(target, visitor, encoder) {
const distinctObjects = new Map();

@@ -398,10 +356,7 @@ const q = [{ obj: target, path: [] }];

const { obj, path } = q.shift();
visitor(new JsonPointer(path), obj);
visitor(encoder(path), obj);
if (shouldDescend(obj)) {
distinctObjects.set(obj, new JsonPointer(path));
distinctObjects.set(obj, new JsonPointer(encodeUriFragmentIdentifier(path)));
if (!Array.isArray(obj)) {
let keys = Object.keys(obj);
if (includeSymbols) {
keys = keys.concat(Object.getOwnPropertySymbols(obj));
}
const keys = Object.keys(obj);
const len = keys.length;

@@ -427,10 +382,10 @@ let i = -1;

// handleArray
let i = -1;
let j = -1;
const len = obj.length;
while (++i < len) {
const it = obj[i];
while (++j < len) {
const it = obj[j];
if (isObject(it) && distinctObjects.has(it)) {
q.push({
obj: new JsonReference(distinctObjects.get(it)),
path: path.concat([i]),
path: path.concat([j + '']),
});

@@ -441,3 +396,3 @@ }

obj: it,
path: path.concat([i]),
path: path.concat([j + '']),
});

@@ -451,132 +406,8 @@ }

/** @hidden */
const $get = Symbol('$get');
const $ptr = Symbol('pointer');
/** @hidden */
const $frg = Symbol('$frg');
const $frg = Symbol('fragmentId');
/** @hidden */
const $symbols = Symbol('$symbols');
const $get = Symbol('getter');
/**
* Symbol used to cache pre-compiled getters on target objects used with static
* pointer methods.
* @hidden
*/
const $cache = Symbol('$cache');
/**
* Enables pointer caching for the specified object. Pointer caching can save
* processing cycles when frequently executing pointer operations against an
* object, using transient JsonPointer instances, such as those used by static
* methods like [[JsonPointer.get]].
*
* The cache gets cleaned up with the target instance, when the target goes out
* of scope.
* @param target the object on which pointer caching will be enabled.
* @returns the target object
*/
const enablePointerCaching = (target) => {
const caching = target;
let cache = caching[$cache];
if (!cache) {
cache = new Map();
caching[$cache] = cache;
}
return target;
};
const disablePointerCaching = (target) => {
const caching = target;
if (caching[$cache]) {
delete caching[$cache];
}
return target;
};
function countSymbols(path) {
let symbols = path[$symbols];
if (typeof symbols === 'undefined') {
symbols = [];
const certainlyPath = path;
let i = -1;
const len = certainlyPath.length;
while (++i < len) {
if (typeof certainlyPath[i] === 'symbol') {
symbols.push(i);
}
}
path[$symbols] = symbols;
}
return symbols;
}
function resolveGetterOrCompile(ptr, target, getter) {
const { pointer, path } = ptr;
const symbols = countSymbols(path);
const cache = target[$cache];
if (cache) {
// the object has a pointer cache.
let records = cache.get(pointer);
if (!records) {
// the object has not seen this pointer
getter = getter || compilePointerDereference(path);
records = [[symbols, path, getter]];
cache.set(pointer, records);
return getter;
}
// There should only be a few, because it requires symbols at the same path
// segment, with the same name, but different symbol scope. Possible but
// unlikely.
for (const [s, p, g] of records) {
if (s.length == symbols.length) {
// somewhat unroll the loops
switch (s.length) {
case 0:
return g;
case 1:
if (s[0] === symbols[0] && p[s[0]] === path[symbols[0]])
return g;
break;
case 2:
if (s[0] === symbols[0] &&
p[s[0]] === path[symbols[0]] &&
s[1] === symbols[1] &&
p[s[1]] === path[symbols[1]])
return g;
break;
case 3:
if (s[0] === symbols[0] &&
p[s[0]] === path[symbols[0]] &&
s[1] === symbols[1] &&
p[s[1]] === path[symbols[1]] &&
s[2] === symbols[2] &&
p[s[2]] === path[symbols[2]])
return g;
break;
default:
// ok, more than 3, so loop
if (s[0] === symbols[0] &&
p[s[0]] === path[symbols[0]] &&
s[1] === symbols[1] &&
p[s[1]] === path[symbols[1]] &&
s[2] === symbols[2] &&
p[s[2]] === path[symbols[2]] &&
s[3] === symbols[3] &&
p[s[3]] === path[symbols[3]]) {
// loop over the remainder...
let seemsEqual = true;
let j = 3;
const len = s.length;
while (seemsEqual && ++j < len) {
seemsEqual =
s[j] === symbols[j] && p[s[j]] === path[symbols[j]];
}
if (seemsEqual)
return g;
}
break;
}
}
}
// We get here if there isn't a match in the cache.
getter = getter || compilePointerDereference(path);
records.push([symbols, path, getter]);
return getter;
}
return getter || compilePointerDereference(path);
}
/**
* Represents a JSON Pointer, capable of getting and setting the value on target

@@ -691,16 +522,6 @@ * objects at the pointer's location.

* Creates a new instance.
*
* If [[ptr]] is another [[JsonPointer]] then consider this a copy constructor.
* @param ptr a string representation of a JSON Pointer, a decoded array of path segments, or another JsonPointer.
* @param ptr a string representation of a JSON Pointer, or a decoded array of path segments.
*/
constructor(ptr) {
if (ptr instanceof JsonPointer) {
// copy construct...
this.path = ptr.path;
this.pointer = ptr.pointer;
this[$get] = ptr[$get];
return;
}
const path = (this.path = decodePtrInit(ptr));
this.pointer = encodePointer(path);
this.path = decodePtrInit(ptr);
}

@@ -861,41 +682,27 @@ /**

* @param visitor a callback function invoked for each unique pointer location in the object graph
* @param includeSymbols indicates whether the results should include paths across symbols (these don't round-trip to legitimate JSON Pointers)
* @param fragmentId indicates whether the visitor should receive fragment identifiers or regular pointers
*/
static visit(target, visitor, includeSymbols = false) {
descendingVisit(target, visitor, includeSymbols);
static visit(target, visitor, fragmentId = false) {
descendingVisit(target, visitor, fragmentId ? encodeUriFragmentIdentifier : encodePointer);
}
/**
* Evaluates the target's object graph, returning a [[PointerPair]] for each location in the graph.
* @param target the target of the operation
* @param includeSymbols indicates whether the results should include paths across symbols (these don't round-trip to legitimate JSON Pointers)
*/
static listPairs(target, includeSymbols = false) {
const res = [];
descendingVisit(target, (pointer, value) => {
res.push([pointer, value]);
}, includeSymbols);
return res;
}
/**
* Evaluates the target's object graph, returning a [[JsonStringPointerListItem]] for each location in the graph.
* @param target the target of the operation
* @param includeSymbols indicates whether the results should include paths across symbols (these don't round-trip to legitimate JSON Pointers)
*/
static listPointers(target, includeSymbols = false) {
static listPointers(target) {
const res = [];
descendingVisit(target, (pointer, value) => {
res.push({ pointer: pointer.pointer, value });
}, includeSymbols);
res.push({ pointer, value });
}, encodePointer);
return res;
}
/**
* Evaluates the target's object graph, returning a [[JsonStringPointerListItem]] for each location in the graph.
* Evaluates the target's object graph, returning a [[UriFragmentIdentifierPointerListItem]] for each location in the graph.
* @param target the target of the operation
* @param includeSymbols indicates whether the results should include paths across symbols (these don't round-trip to legitimate JSON Pointers)
*/
static listFragmentIds(target, includeSymbols = false) {
static listFragmentIds(target) {
const res = [];
descendingVisit(target, (pointer, value) => {
res.push({ fragmentId: pointer.uriFragmentIdentifier, value });
}, includeSymbols);
descendingVisit(target, (fragmentId, value) => {
res.push({ fragmentId, value });
}, encodeUriFragmentIdentifier);
return res;

@@ -906,20 +713,11 @@ }

* @param target the target of the operation
* @param includeSymbols indicates whether the results should include paths across symbols (these don't round-trip to legitimate JSON Pointers)
* @param fragmentId indicates whether the results are populated with fragment identifiers rather than regular pointers
*/
static flatten(target, includeSymbols = false) {
static flatten(target, fragmentId = false) {
const res = {};
descendingVisit(target, (pointer, value) => {
res[pointer.pointer] = value;
}, includeSymbols);
descendingVisit(target, (p, v) => {
res[p] = v;
}, fragmentId ? encodeUriFragmentIdentifier : encodePointer);
return res;
}
static pointersWithSymbol(target, sym) {
const res = [];
descendingVisit(target, (pointer) => {
if (~pointer.path.indexOf(sym)) {
res.push(pointer);
}
}, true);
return res;
}
/**

@@ -929,10 +727,6 @@ * Evaluates the target's object graph, returning a Map&lt;Pointer,unknown> populated with pointers and the corresponding values form the graph.

* @param fragmentId indicates whether the results are populated with fragment identifiers rather than regular pointers
* @param includeSymbols indicates whether the results should include paths across symbols (these don't round-trip to legitimate JSON Pointers)
*/
static map(target, fragmentId = false, includeSymbols = false) {
static map(target, fragmentId = false) {
const res = new Map();
const encoder = fragmentId ? encodeUriFragmentIdentifier : encodePointer;
descendingVisit(target, (p, v) => {
res.set(encoder(p.path), v);
}, includeSymbols);
descendingVisit(target, res.set.bind(res), fragmentId ? encodeUriFragmentIdentifier : encodePointer);
return res;

@@ -946,5 +740,5 @@ }

if (!this[$get]) {
this[$get] = resolveGetterOrCompile(this, target);
this[$get] = compilePointerDereference(this.path);
}
return this[$get](this.path, target);
return this[$get](target);
}

@@ -1043,2 +837,11 @@ /**

/**
* This pointer's JSON Pointer encoded string representation.
*/
get pointer() {
if (this[$ptr] === undefined) {
this[$ptr] = encodePointer(this.path);
}
return this[$ptr];
}
/**
* This pointer's URI fragment identifier encoded string representation.

@@ -1059,42 +862,2 @@ */

}
/**
* Re-export of [[JsonPointer.create]] to support classic API
*/
const create = JsonPointer.create;
/**
* Re-export of [[JsonPointer.get]] to support classic API
*/
const get = JsonPointer.get;
/**
* Re-export of [[JsonPointer.set]] to support classic API
*/
const set = JsonPointer.set;
/**
* Re-export of [[JsonPointer.unset]] to support classic API
*/
const unset = JsonPointer.unset;
/**
* Re-export of [[JsonPointer.decode]] to support classic API
*/
const decode = JsonPointer.decode;
/**
* Re-export of [[JsonPointer.visit]] to support classic API
*/
const visit = JsonPointer.visit;
/**
* Re-export of [[JsonPointer.listPointers]] to support classic API
*/
const listPointers = JsonPointer.listPointers;
/**
* Re-export of [[JsonPointer.listFragmentIds]] to support classic API
*/
const listFragmentIds = JsonPointer.listFragmentIds;
/**
* Re-export of [[JsonPointer.flatten]] to support classic API
*/
const flatten = JsonPointer.flatten;
/**
* Re-export of [[JsonPointer.map]] to support classic API
*/
const map = JsonPointer.map;
/** @hidden */

@@ -1150,3 +913,3 @@ const $pointer = Symbol('pointer');

export { JsonPointer, JsonReference, compilePointerDereference, create, decode, decodeFragmentSegments, decodePointer, decodePointerSegments, decodePtrInit, decodeRelativePointer, decodeUriFragmentIdentifier, disablePointerCaching, enablePointerCaching, encodeFragmentSegments, encodePointer, encodePointerSegments, encodeUriFragmentIdentifier, flatten, get, listFragmentIds, listPointers, looksLikeFragment, map, pickDecoder, replace, set, setValueAtPath, toArrayIndexReference, unset, unsetValueAtPath, visit };
export { JsonPointer, JsonReference, compilePointerDereference, decodeFragmentSegments, decodePointer, decodePointerSegments, decodePtrInit, decodeRelativePointer, decodeUriFragmentIdentifier, encodeFragmentSegments, encodePointer, encodePointerSegments, encodeUriFragmentIdentifier, looksLikeFragment, pickDecoder, replace, setValueAtPath, toArrayIndexReference, unsetValueAtPath };
//# sourceMappingURL=index.js.map

2

dist/json-ptr.min.js

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("JsonPointer",[],t):"object"==typeof exports?exports.JsonPointer=t():e.JsonPointer=t()}(self,(function(){return(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e,t,r){for(var n="",o=e,i=0,a=-1;(a=o.indexOf(t))>-1;)n+=e.substring(i,i+a)+r,o=o.substring(a+t.length,o.length),i+=a+t.length;return o.length>0&&(n+=e.substring(e.length-o.length,e.length)),n}function n(e){for(var t=-1,n=e.length,o=new Array(n);++t<n;)"string"==typeof e[t]?o[t]=r(r(decodeURIComponent(e[t]),"~1","/"),"~0","~"):o[t]=e[t];return o}function o(e){for(var t=-1,n=e.length,o=new Array(n);++t<n;)"string"==typeof e[t]?o[t]=encodeURIComponent(r(r(e[t],"~","~0"),"/","~1")):"symbol"==typeof e[t]?o[t]="Symbol(".concat(e[t].description,")"):o[t]=e[t];return o}function i(e){for(var t=-1,n=e.length,o=new Array(n);++t<n;)"string"==typeof e[t]?o[t]=r(r(e[t],"~1","/"),"~0","~"):o[t]=e[t];return o}function a(e){for(var t=-1,n=e.length,o=new Array(n);++t<n;)"string"==typeof e[t]?o[t]=r(r(e[t],"~","~0"),"/","~1"):"symbol"==typeof e[t]?o[t]="Symbol(".concat(e[t].description,")"):o[t]=e[t];return o}function s(e){if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length)return[];if("/"!==e[0])throw new ReferenceError("Invalid JSON Pointer syntax. Non-empty pointer must begin with a solidus `/`.");return i(e.substring(1).split("/"))}function f(e){if(!e||e&&!Array.isArray(e))throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"":"/".concat(a(e).join("/"))}function u(e){if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length||"#"!==e[0])throw new ReferenceError("Invalid JSON Pointer syntax; URI fragment identifiers must begin with a hash.");if(1===e.length)return[];if("/"!==e[1])throw new ReferenceError("Invalid JSON Pointer syntax.");return n(e.substring(2).split("/"))}function p(e){if(!e||e&&!Array.isArray(e))throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"#":"#/".concat(o(e).join("/"))}e.r(t),e.d(t,{JsonPointer:()=>k,JsonReference:()=>W,compilePointerDereference:()=>g,create:()=>x,decode:()=>_,decodeFragmentSegments:()=>n,decodePointer:()=>s,decodePointerSegments:()=>i,decodePtrInit:()=>w,decodeRelativePointer:()=>l,decodeUriFragmentIdentifier:()=>u,disablePointerCaching:()=>R,enablePointerCaching:()=>O,encodeFragmentSegments:()=>o,encodePointer:()=>f,encodePointerSegments:()=>a,encodeUriFragmentIdentifier:()=>p,flatten:()=>M,get:()=>F,listFragmentIds:()=>U,listPointers:()=>$,looksLikeFragment:()=>v,map:()=>D,pickDecoder:()=>b,replace:()=>r,set:()=>N,setValueAtPath:()=>y,toArrayIndexReference:()=>h,unset:()=>T,unsetValueAtPath:()=>d,visit:()=>C});var c="Invalid Relative JSON Pointer syntax. Relative pointer must begin with a non-negative integer, followed by either the number sign (#), or a JSON Pointer.";function l(e){if("string"!=typeof e)throw new TypeError("Invalid type: Relative JSON Pointers are represented as strings.");if(0===e.length)throw new ReferenceError(c);var t=e.split("/"),r=t[0];if("#"==r[r.length-1]){if(t.length>1)throw new ReferenceError(c);r=r.substring(0,r.length-1)}for(var n=-1,o=r.length;++n<o;)if(r[n]<"0"||r[n]>"9")throw new ReferenceError(c);var a=i(t.slice(1));return a.unshift(t[0]),a}function h(e,t){if("number"==typeof t)return t;if("symbol"==typeof t)return t;var r=t.length;if(!r)return-1;var n=0;if(1===r&&"-"===t[0])return Array.isArray(e)?e.length:0;for(;++n<r;)if(t[n]<"0"||t[n]>"9")return-1;return parseInt(t,10)}function g(e){var t="if (typeof(it) !== 'undefined'";if(0===e.length)return function(e,t){return t};for(var n=-1,o=e.length;++n<o;){if("symbol"==typeof e[n])t=t+"\n\t&& it !== null && typeof((it = it[path["+n+"]])) !== 'undefined'";else t=t+"\n\t&& it !== null && typeof((it = it['"+r(r(e[n]+"","\\","\\\\"),"'","\\'")+"'])) !== 'undefined'"}return t+=") {\n\treturn it;\n }",new Function("path","it",t)}function y(e,t,r,n){if(void 0===n&&(n=!1),0===r.length)throw new Error("Cannot set the root object; assign it directly.");if(void 0===e)throw new TypeError("Cannot set values on undefined");for(var o,i=e,a=r.length,s=r.length-1,f=-1;++f<a;){var u=r[f];if("string"!=typeof u&&"number"!=typeof u&&"symbol"!=typeof u)throw new TypeError("PathSegments must be a string, number, or symbol.");if("__proto__"===u||"constructor"===u||"prototype"===u)throw new Error("Attempted prototype pollution disallowed.");if(Array.isArray(i)){if("-"===u&&f===s)return void i.push(t);var p=h(i,u);if("symbol"==typeof p){if(f===s){o=i[p],i[p]=t;break}i=i[p]}else if(i.length>p){if(f===s){o=i[p],i[p]=t;break}i=i[p]}else if(f===s&&p===i.length){if(n)return void i.push(t)}else n&&(i=i[p]=f===s?t:{})}else{if(void 0===i[u]){if(n){if(f===s)return void(i[u]=t);var c=Number(r[f+1]);if(Number.isInteger(c)&&-1!==h(i[u],c)){i=i[u]=[];continue}i=i[u]={};continue}return}if(f===s){o=i[u],i[u]=t;break}i=i[u]}}return o}function d(e,t){if(0===t.length)throw new Error("Cannot unset the root object; assign it directly.");if(void 0===e)throw new TypeError("Cannot unset values on undefined");for(var r,n=e,o=t.length,i=t.length-1,a=-1;++a<o;){var s=t[a];if("string"!=typeof s&&"number"!=typeof s)throw new TypeError("PathSegments must be a string or a number.");if("__proto__"===s||"constructor"===s||"prototype"===s)throw new Error("Attempted prototype pollution disallowed.");if(Array.isArray(n)){var f=h(n,s);if("symbol"==typeof f){if(a===i){r=n[f],delete n[f];break}n=n[f]}else{if(f>=n.length)return;if(a===i){r=n[f],delete n[f];break}n=n[f]}}else{if(void 0===n[s])return;if(a===i){r=n[s],delete n[s];break}n=n[s]}}return r}function v(e){return"string"==typeof e&&e.length>0&&"#"===e[0]}function b(e){return v(e)?u:s}function w(e){return Array.isArray(e)?e.slice(0):b(e)(e)}function m(e){return"object"==typeof e&&null!==e}function P(e){return m(e)&&!W.isReference(e)}function A(e,t,r){void 0===r&&(r=!1);for(var n=new Map,o=[{obj:e,path:[]}];o.length;){var i=o.shift(),a=i.obj,s=i.path;if(t(new k(s),a),P(a))if(n.set(a,new k(s)),Array.isArray(a))for(c=-1,p=a.length;++c<p;){var f=a[c];m(f)&&n.has(f)?o.push({obj:new W(n.get(f)),path:s.concat([c])}):o.push({obj:f,path:s.concat([c])})}else{var u=Object.keys(a);r&&(u=u.concat(Object.getOwnPropertySymbols(a)));for(var p=u.length,c=-1;++c<p;){var l=a[u[c]];m(l)&&n.has(l)?o.push({obj:new W(n.get(l)),path:s.concat(u[c])}):o.push({obj:l,path:s.concat(u[c])})}}}}var S=Symbol("$get"),I=Symbol("$frg"),j=Symbol("$symbols"),E=Symbol("$cache"),O=function(e){var t=e,r=t[E];return r||(r=new Map,t[E]=r),e},R=function(e){var t=e;return t[E]&&delete t[E],e};function J(e,t,r){var n=e.pointer,o=e.path,i=function(e){var t=e[j];if(void 0===t){t=[];for(var r=e,n=-1,o=r.length;++n<o;)"symbol"==typeof r[n]&&t.push(n);e[j]=t}return t}(o),a=t[E];if(a){var s=a.get(n);if(!s)return s=[[i,o,r=r||g(o)]],a.set(n,s),r;for(var f=0,u=s;f<u.length;f++){var p=u[f],c=p[0],l=p[1],h=p[2];if(c.length==i.length)switch(c.length){case 0:return h;case 1:if(c[0]===i[0]&&l[c[0]]===o[i[0]])return h;break;case 2:if(c[0]===i[0]&&l[c[0]]===o[i[0]]&&c[1]===i[1]&&l[c[1]]===o[i[1]])return h;break;case 3:if(c[0]===i[0]&&l[c[0]]===o[i[0]]&&c[1]===i[1]&&l[c[1]]===o[i[1]]&&c[2]===i[2]&&l[c[2]]===o[i[2]])return h;break;default:if(c[0]===i[0]&&l[c[0]]===o[i[0]]&&c[1]===i[1]&&l[c[1]]===o[i[1]]&&c[2]===i[2]&&l[c[2]]===o[i[2]]&&c[3]===i[3]&&l[c[3]]===o[i[3]]){for(var y=!0,d=3,v=c.length;y&&++d<v;)y=c[d]===i[d]&&l[c[d]]===o[i[d]];if(y)return h}}}return r=r||g(o),s.push([i,o,r]),r}return r||g(o)}var k=function(){function e(t){if(t instanceof e)return this.path=t.path,this.pointer=t.pointer,void(this[S]=t[S]);var r=this.path=w(t);this.pointer=f(r)}return e.create=function(t){return new e(t)},e.has=function(t,r){return("string"==typeof r||Array.isArray(r))&&(r=new e(r)),r.has(t)},e.get=function(t,r){return("string"==typeof r||Array.isArray(r))&&(r=new e(r)),r.get(t)},e.set=function(t,r,n,o){return void 0===o&&(o=!1),("string"==typeof r||Array.isArray(r))&&(r=new e(r)),r.set(t,n,o)},e.unset=function(t,r){return("string"==typeof r||Array.isArray(r))&&(r=new e(r)),r.unset(t)},e.decode=function(e){return b(e)(e)},e.visit=function(e,t,r){void 0===r&&(r=!1),A(e,t,r)},e.listPairs=function(e,t){void 0===t&&(t=!1);var r=[];return A(e,(function(e,t){r.push([e,t])}),t),r},e.listPointers=function(e,t){void 0===t&&(t=!1);var r=[];return A(e,(function(e,t){r.push({pointer:e.pointer,value:t})}),t),r},e.listFragmentIds=function(e,t){void 0===t&&(t=!1);var r=[];return A(e,(function(e,t){r.push({fragmentId:e.uriFragmentIdentifier,value:t})}),t),r},e.flatten=function(e,t){void 0===t&&(t=!1);var r={};return A(e,(function(e,t){r[e.pointer]=t}),t),r},e.pointersWithSymbol=function(e,t){var r=[];return A(e,(function(e){~e.path.indexOf(t)&&r.push(e)}),!0),r},e.map=function(e,t,r){void 0===t&&(t=!1),void 0===r&&(r=!1);var n=new Map,o=t?p:f;return A(e,(function(e,t){n.set(o(e.path),t)}),r),n},e.prototype.get=function(e){return this[S]||(this[S]=J(this,e)),this[S](this.path,e)},e.prototype.set=function(e,t,r){return void 0===r&&(r=!1),y(e,t,this.path,r)},e.prototype.unset=function(e){return d(e,this.path)},e.prototype.has=function(e){return void 0!==this.get(e)},e.prototype.parent=function(t){var r=this.path;if(1!=r.length)return new e(r.slice(0,r.length-1)).get(t)},e.prototype.relative=function(t){var r=this.path,n=l(t),o=parseInt(n[0]);if(o>r.length)throw new Error("Relative location does not exist.");var i=r.slice(0,r.length-o).concat(n.slice(1));if("#"==n[0][n[0].length-1]){var a=i[i.length-1];throw new Error("We won't compile a pointer that will always return '".concat(a,"'. Use JsonPointer.rel(target, ptr) instead."))}return new e(i)},e.prototype.rel=function(t,r){var n=this.path,o=l(r),i=parseInt(o[0]);if(!(i>n.length)){var a=n.slice(0,n.length-i).concat(o.slice(1)),s=new e(a);if("#"==o[0][o[0].length-1]){var f=a[a.length-1],u=s.parent(t);return Array.isArray(u)?parseInt(f,10):f}return s.get(t)}},e.prototype.concat=function(t){return new e(this.path.concat(t instanceof e?t.path:w(t)))},Object.defineProperty(e.prototype,"uriFragmentIdentifier",{get:function(){return this[I]||(this[I]=p(this.path)),this[I]},enumerable:!1,configurable:!0}),e.prototype.toString=function(){return this.pointer},e}(),x=k.create,F=k.get,N=k.set,T=k.unset,_=k.decode,C=k.visit,$=k.listPointers,U=k.listFragmentIds,M=k.flatten,D=k.map,V=Symbol("pointer"),W=function(){function e(e){this[V]=e instanceof k?e:new k(e),this.$ref=this[V].uriFragmentIdentifier}return e.isReference=function(e){if(!e)return!1;var t=e;return"string"==typeof t.$ref&&"function"==typeof t.resolve},e.prototype.resolve=function(e){return this[V].get(e)},e.prototype.pointer=function(){return this[V]},e.prototype.toString=function(){return this.$ref},e}();return t})()}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("JsonPointer",[],t):"object"==typeof exports?exports.JsonPointer=t():e.JsonPointer=t()}(self,(function(){return(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e,t,r){for(var n="",o=e,i=0,a=-1;(a=o.indexOf(t))>-1;)n+=e.substring(i,i+a)+r,o=o.substring(a+t.length,o.length),i+=a+t.length;return o.length>0&&(n+=e.substring(e.length-o.length,e.length)),n}function n(e){for(var t=-1,n=e.length,o=new Array(n);++t<n;)"string"==typeof e[t]?o[t]=r(r(decodeURIComponent(e[t]),"~1","/"),"~0","~"):o[t]=e[t];return o}function o(e){for(var t=-1,n=e.length,o=new Array(n);++t<n;)"string"==typeof e[t]?o[t]=encodeURIComponent(r(r(e[t],"~","~0"),"/","~1")):o[t]=e[t];return o}function i(e){for(var t=-1,n=e.length,o=new Array(n);++t<n;)"string"==typeof e[t]?o[t]=r(r(e[t],"~1","/"),"~0","~"):o[t]=e[t];return o}function a(e){for(var t=-1,n=e.length,o=new Array(n);++t<n;)"string"==typeof e[t]?o[t]=r(r(e[t],"~","~0"),"/","~1"):o[t]=e[t];return o}function s(e){if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length)return[];if("/"!==e[0])throw new ReferenceError("Invalid JSON Pointer syntax. Non-empty pointer must begin with a solidus `/`.");return i(e.substring(1).split("/"))}function f(e){if(!e||e&&!Array.isArray(e))throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"":"/".concat(a(e).join("/"))}function u(e){if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length||"#"!==e[0])throw new ReferenceError("Invalid JSON Pointer syntax; URI fragment identifiers must begin with a hash.");if(1===e.length)return[];if("/"!==e[1])throw new ReferenceError("Invalid JSON Pointer syntax.");return n(e.substring(2).split("/"))}function p(e){if(!e||e&&!Array.isArray(e))throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"#":"#/".concat(o(e).join("/"))}e.r(t),e.d(t,{JsonPointer:()=>E,JsonReference:()=>O,compilePointerDereference:()=>g,decodeFragmentSegments:()=>n,decodePointer:()=>s,decodePointerSegments:()=>i,decodePtrInit:()=>b,decodeRelativePointer:()=>h,decodeUriFragmentIdentifier:()=>u,encodeFragmentSegments:()=>o,encodePointer:()=>f,encodePointerSegments:()=>a,encodeUriFragmentIdentifier:()=>p,looksLikeFragment:()=>v,pickDecoder:()=>w,replace:()=>r,setValueAtPath:()=>y,toArrayIndexReference:()=>l,unsetValueAtPath:()=>d});var c="Invalid Relative JSON Pointer syntax. Relative pointer must begin with a non-negative integer, followed by either the number sign (#), or a JSON Pointer.";function h(e){if("string"!=typeof e)throw new TypeError("Invalid type: Relative JSON Pointers are represented as strings.");if(0===e.length)throw new ReferenceError(c);var t=e.split("/"),r=t[0];if("#"==r[r.length-1]){if(t.length>1)throw new ReferenceError(c);r=r.substr(0,r.length-1)}for(var n=-1,o=r.length;++n<o;)if(r[n]<"0"||r[n]>"9")throw new ReferenceError(c);var a=i(t.slice(1));return a.unshift(t[0]),a}function l(e,t){if("number"==typeof t)return t;var r=t.length;if(!r)return-1;var n=0;if(1===r&&"-"===t[0])return Array.isArray(e)?e.length:0;for(;++n<r;)if(t[n]<"0"||t[n]>"9")return-1;return parseInt(t,10)}function g(e){var t="if (typeof(it) !== 'undefined'";return 0===e.length?function(e){return e}:(t=e.reduce((function(t,n,o){return t+"\n\t&& it !== null && typeof((it = it['"+r(r(e[o]+"","\\","\\\\"),"'","\\'")+"'])) !== 'undefined'"}),"if (typeof(it) !== 'undefined'"),t+=") {\n\treturn it;\n }",new Function("it",t))}function y(e,t,r,n){if(void 0===n&&(n=!1),0===r.length)throw new Error("Cannot set the root object; assign it directly.");if(void 0===e)throw new TypeError("Cannot set values on undefined");for(var o,i,a,s=e,f=r.length,u=r.length-1,p=-1;++p<f;){if("string"!=typeof(o=r[p])&&"number"!=typeof o)throw new TypeError("PathSegments must be a string or a number.");if("__proto__"===o||"constructor"===o||"prototype"===o)throw new Error("Attempted prototype pollution disallowed.");if(Array.isArray(s)){if("-"===o&&p===u)return void s.push(t);if(a=l(s,o),s.length>a){if(p===u){i=s[a],s[a]=t;break}s=s[a]}else if(p===u&&a===s.length){if(n)return void s.push(t)}else n&&(s=s[a]=p===u?t:{})}else{if(void 0===s[o]){if(n){if(p===u)return void(s[o]=t);var c=Number(r[p+1]);if(Number.isInteger(c)&&-1!==l(s[o],c)){s=s[o]=[];continue}s=s[o]={};continue}return}if(p===u){i=s[o],s[o]=t;break}s=s[o]}}return i}function d(e,t){if(0===t.length)throw new Error("Cannot unset the root object; assign it directly.");if(void 0===e)throw new TypeError("Cannot unset values on undefined");for(var r,n,o,i=e,a=t.length,s=t.length-1,f=-1;++f<a;){if("string"!=typeof(r=t[f])&&"number"!=typeof r)throw new TypeError("PathSegments must be a string or a number.");if("__proto__"===r||"constructor"===r||"prototype"===r)throw new Error("Attempted prototype pollution disallowed.");if(Array.isArray(i)){if((o=l(i,r))>=i.length)return;if(f===s){n=i[o],delete i[o];break}i=i[o]}else{if(void 0===i[r])return;if(f===s){n=i[r],delete i[r];break}i=i[r]}}return n}function v(e){return"string"==typeof e&&e.length>0&&"#"===e[0]}function w(e){return v(e)?u:s}function b(e){return Array.isArray(e)?e.slice(0):w(e)(e)}function m(e){return"object"==typeof e&&null!==e}function A(e){return m(e)&&!O.isReference(e)}function P(e,t,r){for(var n=new Map,o=[{obj:e,path:[]}];o.length;){var i=o.shift(),a=i.obj,s=i.path;if(t(r(s),a),A(a))if(n.set(a,new E(p(s))),Array.isArray(a)){var f=-1;for(h=a.length;++f<h;){var u=a[f];m(u)&&n.has(u)?o.push({obj:new O(n.get(u)),path:s.concat([f+""])}):o.push({obj:u,path:s.concat([f+""])})}}else for(var c=Object.keys(a),h=c.length,l=-1;++l<h;){var g=a[c[l]];m(g)&&n.has(g)?o.push({obj:new O(n.get(g)),path:s.concat(c[l])}):o.push({obj:g,path:s.concat(c[l])})}}}var I=Symbol("pointer"),S=Symbol("fragmentId"),j=Symbol("getter"),E=function(){function e(e){this.path=b(e)}return e.create=function(t){return new e(t)},e.has=function(t,r){return("string"==typeof r||Array.isArray(r))&&(r=new e(r)),r.has(t)},e.get=function(t,r){return("string"==typeof r||Array.isArray(r))&&(r=new e(r)),r.get(t)},e.set=function(t,r,n,o){return void 0===o&&(o=!1),("string"==typeof r||Array.isArray(r))&&(r=new e(r)),r.set(t,n,o)},e.unset=function(t,r){return("string"==typeof r||Array.isArray(r))&&(r=new e(r)),r.unset(t)},e.decode=function(e){return w(e)(e)},e.visit=function(e,t,r){void 0===r&&(r=!1),P(e,t,r?p:f)},e.listPointers=function(e){var t=[];return P(e,(function(e,r){t.push({pointer:e,value:r})}),f),t},e.listFragmentIds=function(e){var t=[];return P(e,(function(e,r){t.push({fragmentId:e,value:r})}),p),t},e.flatten=function(e,t){void 0===t&&(t=!1);var r={};return P(e,(function(e,t){r[e]=t}),t?p:f),r},e.map=function(e,t){void 0===t&&(t=!1);var r=new Map;return P(e,r.set.bind(r),t?p:f),r},e.prototype.get=function(e){return this[j]||(this[j]=g(this.path)),this[j](e)},e.prototype.set=function(e,t,r){return void 0===r&&(r=!1),y(e,t,this.path,r)},e.prototype.unset=function(e){return d(e,this.path)},e.prototype.has=function(e){return void 0!==this.get(e)},e.prototype.parent=function(t){var r=this.path;if(1!=r.length)return new e(r.slice(0,r.length-1)).get(t)},e.prototype.relative=function(t){var r=this.path,n=h(t),o=parseInt(n[0]);if(o>r.length)throw new Error("Relative location does not exist.");var i=r.slice(0,r.length-o).concat(n.slice(1));if("#"==n[0][n[0].length-1]){var a=i[i.length-1];throw new Error("We won't compile a pointer that will always return '".concat(a,"'. Use JsonPointer.rel(target, ptr) instead."))}return new e(i)},e.prototype.rel=function(t,r){var n=this.path,o=h(r),i=parseInt(o[0]);if(!(i>n.length)){var a=n.slice(0,n.length-i).concat(o.slice(1)),s=new e(a);if("#"==o[0][o[0].length-1]){var f=a[a.length-1],u=s.parent(t);return Array.isArray(u)?parseInt(f,10):f}return s.get(t)}},e.prototype.concat=function(t){return new e(this.path.concat(t instanceof e?t.path:b(t)))},Object.defineProperty(e.prototype,"pointer",{get:function(){return void 0===this[I]&&(this[I]=f(this.path)),this[I]},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"uriFragmentIdentifier",{get:function(){return this[S]||(this[S]=p(this.path)),this[S]},enumerable:!1,configurable:!0}),e.prototype.toString=function(){return this.pointer},e}(),R=Symbol("pointer"),O=function(){function e(e){this[R]=e instanceof E?e:new E(e),this.$ref=this[R].uriFragmentIdentifier}return e.isReference=function(e){if(!e)return!1;var t=e;return"string"==typeof t.$ref&&"function"==typeof t.resolve},e.prototype.resolve=function(e){return this[R].get(e)},e.prototype.pointer=function(){return this[R]},e.prototype.toString=function(){return this.$ref},e}();return t})()}));
//# sourceMappingURL=json-ptr.min.js.map

@@ -7,26 +7,10 @@ import { JsonStringPointer, UriFragmentIdentifierPointer, Pointer, RelativeJsonPointer, PathSegments, JsonStringPointerListItem, UriFragmentIdentifierPointerListItem } from './types';

*/
export declare type Visitor = (ptr: JsonPointer, val: unknown) => void;
export declare type Visitor = (ptr: JsonStringPointer, val: unknown) => void;
/** @hidden */
declare const $get: unique symbol;
declare const $ptr: unique symbol;
/** @hidden */
declare const $frg: unique symbol;
/** @hidden */
declare const $get: unique symbol;
/**
* Enables pointer caching for the specified object. Pointer caching can save
* processing cycles when frequently executing pointer operations against an
* object, using transient JsonPointer instances, such as those used by static
* methods like [[JsonPointer.get]].
*
* The cache gets cleaned up with the target instance, when the target goes out
* of scope.
* @param target the object on which pointer caching will be enabled.
* @returns the target object
*/
export declare const enablePointerCaching: (target: unknown) => unknown;
export declare const disablePointerCaching: (target: unknown) => unknown;
/**
* Tuple representing a pointer:value pair.
*/
export declare type PointerPair = [JsonPointer, unknown];
export declare type PointerLike = Pointer | PathSegments | JsonPointer;
/**
* Represents a JSON Pointer, capable of getting and setting the value on target

@@ -140,10 +124,8 @@ * objects at the pointer's location.

/** @hidden */
private [$get];
private [$ptr];
/** @hidden */
private [$frg];
/** @hidden */
private [$get];
/**
* This pointer's JSON Pointer encoded string representation.
*/
readonly pointer: JsonStringPointer;
/**
* Factory function that creates a JsonPointer instance.

@@ -180,3 +162,3 @@ *

*/
static has(target: unknown, pointer: PointerLike): boolean;
static has(target: unknown, pointer: Pointer | PathSegments | JsonPointer): boolean;
/**

@@ -201,3 +183,3 @@ * Gets the `target` object's value at the `pointer`'s location.

*/
static get(target: unknown, pointer: PointerLike): unknown;
static get(target: unknown, pointer: Pointer | PathSegments | JsonPointer): unknown;
/**

@@ -239,3 +221,3 @@ * Sets the `target` object's value, as specified, at the `pointer`'s location.

*/
static set(target: unknown, pointer: PointerLike, val: unknown, force?: boolean): unknown;
static set(target: unknown, pointer: Pointer | PathSegments | JsonPointer, val: unknown, force?: boolean): unknown;
/**

@@ -271,3 +253,3 @@ * Removes the `target` object's value at the `pointer`'s location.

*/
static unset(target: unknown, pointer: PointerLike): unknown;
static unset(target: unknown, pointer: Pointer | PathSegments | JsonPointer): unknown;
/**

@@ -282,30 +264,21 @@ * Decodes the specified pointer into path segments.

* @param visitor a callback function invoked for each unique pointer location in the object graph
* @param includeSymbols indicates whether the results should include paths across symbols (these don't round-trip to legitimate JSON Pointers)
* @param fragmentId indicates whether the visitor should receive fragment identifiers or regular pointers
*/
static visit(target: unknown, visitor: Visitor, includeSymbols?: boolean): void;
static visit(target: unknown, visitor: Visitor, fragmentId?: boolean): void;
/**
* Evaluates the target's object graph, returning a [[PointerPair]] for each location in the graph.
* @param target the target of the operation
* @param includeSymbols indicates whether the results should include paths across symbols (these don't round-trip to legitimate JSON Pointers)
*/
static listPairs(target: unknown, includeSymbols?: boolean): PointerPair[];
/**
* Evaluates the target's object graph, returning a [[JsonStringPointerListItem]] for each location in the graph.
* @param target the target of the operation
* @param includeSymbols indicates whether the results should include paths across symbols (these don't round-trip to legitimate JSON Pointers)
*/
static listPointers(target: unknown, includeSymbols?: boolean): JsonStringPointerListItem[];
static listPointers(target: unknown): JsonStringPointerListItem[];
/**
* Evaluates the target's object graph, returning a [[JsonStringPointerListItem]] for each location in the graph.
* Evaluates the target's object graph, returning a [[UriFragmentIdentifierPointerListItem]] for each location in the graph.
* @param target the target of the operation
* @param includeSymbols indicates whether the results should include paths across symbols (these don't round-trip to legitimate JSON Pointers)
*/
static listFragmentIds(target: unknown, includeSymbols?: boolean): UriFragmentIdentifierPointerListItem[];
static listFragmentIds(target: unknown): UriFragmentIdentifierPointerListItem[];
/**
* Evaluates the target's object graph, returning a Record&lt;Pointer, unknown> populated with pointers and the corresponding values from the graph.
* @param target the target of the operation
* @param includeSymbols indicates whether the results should include paths across symbols (these don't round-trip to legitimate JSON Pointers)
* @param fragmentId indicates whether the results are populated with fragment identifiers rather than regular pointers
*/
static flatten(target: unknown, includeSymbols?: boolean): Record<Pointer, unknown>;
static pointersWithSymbol(target: unknown, sym: symbol): JsonPointer[];
static flatten(target: unknown, fragmentId?: boolean): Record<Pointer, unknown>;
/**

@@ -315,5 +288,4 @@ * Evaluates the target's object graph, returning a Map&lt;Pointer,unknown> populated with pointers and the corresponding values form the graph.

* @param fragmentId indicates whether the results are populated with fragment identifiers rather than regular pointers
* @param includeSymbols indicates whether the results should include paths across symbols (these don't round-trip to legitimate JSON Pointers)
*/
static map(target: unknown, fragmentId?: boolean, includeSymbols?: boolean): Map<string, unknown>;
static map(target: unknown, fragmentId?: boolean): Map<Pointer, unknown>;
/**

@@ -325,7 +297,5 @@ * The pointer's decoded path segments.

* Creates a new instance.
*
* If [[ptr]] is another [[JsonPointer]] then consider this a copy constructor.
* @param ptr a string representation of a JSON Pointer, a decoded array of path segments, or another JsonPointer.
* @param ptr a string representation of a JSON Pointer, or a decoded array of path segments.
*/
constructor(ptr: PointerLike);
constructor(ptr: Pointer | PathSegments);
/**

@@ -382,4 +352,8 @@ * Gets the target object's value at the pointer's location.

*/
concat(ptr: PointerLike): JsonPointer;
concat(ptr: JsonPointer | Pointer | PathSegments): JsonPointer;
/**
* This pointer's JSON Pointer encoded string representation.
*/
get pointer(): JsonStringPointer;
/**
* This pointer's URI fragment identifier encoded string representation.

@@ -393,42 +367,2 @@ */

}
/**
* Re-export of [[JsonPointer.create]] to support classic API
*/
export declare const create: typeof JsonPointer.create;
/**
* Re-export of [[JsonPointer.get]] to support classic API
*/
export declare const get: typeof JsonPointer.get;
/**
* Re-export of [[JsonPointer.set]] to support classic API
*/
export declare const set: typeof JsonPointer.set;
/**
* Re-export of [[JsonPointer.unset]] to support classic API
*/
export declare const unset: typeof JsonPointer.unset;
/**
* Re-export of [[JsonPointer.decode]] to support classic API
*/
export declare const decode: typeof JsonPointer.decode;
/**
* Re-export of [[JsonPointer.visit]] to support classic API
*/
export declare const visit: typeof JsonPointer.visit;
/**
* Re-export of [[JsonPointer.listPointers]] to support classic API
*/
export declare const listPointers: typeof JsonPointer.listPointers;
/**
* Re-export of [[JsonPointer.listFragmentIds]] to support classic API
*/
export declare const listFragmentIds: typeof JsonPointer.listFragmentIds;
/**
* Re-export of [[JsonPointer.flatten]] to support classic API
*/
export declare const flatten: typeof JsonPointer.flatten;
/**
* Re-export of [[JsonPointer.map]] to support classic API
*/
export declare const map: typeof JsonPointer.map;
/** @hidden */

@@ -458,3 +392,3 @@ declare const $pointer: unique symbol;

*/
constructor(pointer: PointerLike);
constructor(pointer: JsonPointer | Pointer | PathSegments);
/**

@@ -461,0 +395,0 @@ * Resolves the reference against the `target` object, returning the value at

@@ -1,3 +0,2 @@

export declare type SafePathSegment = string | number;
export declare type PathSegment = SafePathSegment | symbol;
export declare type PathSegment = string | number;
export declare type PathSegments = PathSegment[];

@@ -4,0 +3,0 @@ export declare type JsonStringPointer = string;

@@ -12,4 +12,4 @@ import { JsonStringPointer, UriFragmentIdentifierPointer, Pointer, RelativeJsonPointer, PathSegment, PathSegments, Decoder } from './types';

export declare function decodeRelativePointer(ptr: RelativeJsonPointer): PathSegments;
export declare function toArrayIndexReference(arr: readonly unknown[], idx: PathSegment): number | symbol;
export declare type Dereference = (path: PathSegments, it: unknown) => unknown;
export declare function toArrayIndexReference(arr: readonly unknown[], idx: PathSegment): number;
export declare type Dereference = (it: unknown) => unknown;
export declare function compilePointerDereference(path: PathSegments): Dereference;

@@ -16,0 +16,0 @@ export declare function setValueAtPath(target: unknown, val: unknown, path: PathSegments, force?: boolean): unknown;

{
"name": "json-ptr",
"version": "3.1.1-symbols.0e6db58",
"version": "3.1.2-main.1988f05",
"author": "Phillip Clark <phillip@flitbit.com>",

@@ -17,2 +17,3 @@ "description": "A complete implementation of JSON Pointer (RFC 6901) for nodejs and modern browsers.",

".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/esm/index.js",

@@ -19,0 +20,0 @@ "require": "./dist/cjs/index.js"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc