@hyperjump/json-pointer
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -37,4 +37,5 @@ const curry = require("just-curry-it"); | ||
} else if (Array.isArray(subject)) { | ||
const clonedSubject = { ...subject }; | ||
clonedSubject[pointer[0]] = value; | ||
const clonedSubject = [...subject]; | ||
const segment = computeSegment(subject, pointer[0]); | ||
clonedSubject[segment] = value; | ||
return clonedSubject; | ||
@@ -58,3 +59,3 @@ } else if (typeof subject === "object" && subject !== null) { | ||
} else if (pointer.length === 1 && !isScalar(subject)) { | ||
const segment = pointer[0]; | ||
const segment = computeSegment(subject, pointer[0]); | ||
subject[segment] = value; | ||
@@ -83,2 +84,3 @@ } else { | ||
} else if (typeof subject === "object" && subject !== null) { | ||
// eslint-disable-next-line no-unused-vars | ||
const { [pointer[0]]: _, ...result } = subject; | ||
@@ -116,3 +118,4 @@ return result; | ||
const escape = (segment) => segment.toString().replace(/~/g, "~0").replace(/\//g, "~1"); | ||
const unescape = (segment) => segment.toString().replace(/~0/g, "~").replace(/~1/g, "/"); | ||
const unescape = (segment) => segment.toString().replace(/~1/g, "/").replace(/~0/g, "~"); | ||
const computeSegment = (value, segment) => Array.isArray(value) && segment === "-" ? value.length : segment; | ||
@@ -122,7 +125,10 @@ const applySegment = (value, segment, cursor = "") => { | ||
throw Error(`Value at '${cursor}' is a scalar and can't be indexed`); | ||
} else if (!(segment in value)) { | ||
throw Error(`Value at '${cursor}' does not have index '${segment}'`); | ||
} | ||
return value[segment]; | ||
const computedSegment = computeSegment(value, segment); | ||
if (!(computedSegment in value)) { | ||
throw Error(`Value at '${cursor}' does not have index '${computedSegment}'`); | ||
} | ||
return value[computedSegment]; | ||
}; | ||
@@ -129,0 +135,0 @@ |
{ | ||
"name": "@hyperjump/json-pointer", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "An RFC-6901 JSON Pointer implementation", | ||
@@ -5,0 +5,0 @@ "main": "lib/json-pointer.js", |
@@ -48,7 +48,7 @@ JSON Pointer | ||
// New value is returned without modifying the original | ||
const deleteFooBar = JsonPointer.unset(fooBarPointer); | ||
const unsetFooBar = JsonPointer.unset(fooBarPointer); | ||
setFooBar(value); // { "foo": {} } | ||
// Delete a value from a pointer | ||
// New value is returned without modifying the original | ||
// The original value is changed and no value is returned | ||
const deleteFooBar = JsonPointer.delete(fooBarPointer); | ||
@@ -55,0 +55,0 @@ setFooBar(value); // { "foo": {} } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7979
111