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

@hyperjump/json-pointer

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hyperjump/json-pointer - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

20

lib/json-pointer.js

@@ -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": {} }

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