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.4.0 to 0.5.0

27

lib/json-pointer.js

@@ -35,4 +35,3 @@ const curry = require("just-curry-it");

const segment = pointer.shift();
subject[segment] = _set(pointer, applySegment(subject, segment, cursor), value, append(segment, cursor));
return subject;
return { ...subject, [segment]: _set(pointer, applySegment(subject, segment, cursor), value, append(segment, cursor)) };
} else if (Array.isArray(subject)) {

@@ -49,2 +48,20 @@ const clonedSubject = subject.map((a) => a);

const mutate = (pointer, subject = undefined, value = undefined) => {
const ptr = compile(pointer);
const fn = curry((subject, value) => _mutate(ptr, subject, value, nil));
return subject === undefined ? fn : fn(subject, value);
};
const _mutate = (pointer, subject, value, cursor) => {
if (pointer.length === 0) {
return;
} else if (pointer.length === 1 && !isScalar(subject)) {
const segment = pointer[0];
subject[segment] = value;
} else {
const segment = pointer.shift();
_mutate(pointer, applySegment(subject, segment, cursor), value, append(segment, cursor));
}
};
const append = curry((segment, pointer) => pointer + "/" + escape(segment));

@@ -56,3 +73,3 @@

const applySegment = (value, segment, cursor = "") => {
if (value === null || typeof value !== "object") {
if (isScalar(value)) {
throw Error(`Value at '${cursor}' is a scalar and can't be indexed`);

@@ -66,2 +83,4 @@ } else if (!(segment in value)) {

module.exports = { nil, get, set, append };
const isScalar = (value) => value === null || typeof value !== "object";
module.exports = { nil, get, set, mutate, append };

2

package.json
{
"name": "@hyperjump/json-pointer",
"version": "0.4.0",
"version": "0.5.0",
"description": "An RFC-6901 JSON Pointer implementation",

@@ -5,0 +5,0 @@ "main": "lib/json-pointer.js",

@@ -37,4 +37,10 @@ JSON Pointer

// Set value from pointer
// New value is returned without modifying the original
const setFooBar = JsonPointer.set(fooBarPointer);
getFooBar(value, 33); // 33
setFooBar(value, 33); // { "foo": { "bar": 33 } }
// Mutate value from pointer
// The original value is changed and no value is returned
const mutateFooBar = JsonPointer.mutate(fooBarPointer);
mutateFooBar(value, 33); // { "foo": { "bar": 33 } }
```

@@ -41,0 +47,0 @@

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