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

fast-json-patch

Package Overview
Dependencies
Maintainers
2
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-json-patch - npm Package Compare versions

Comparing version 0.5.2 to 0.5.3

2

dist/json-patch-duplex.min.js
/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js version: 0.5.2
* json-patch-duplex.js version: 0.5.3
* (c) 2013 Joachim Wester

@@ -5,0 +5,0 @@ * MIT license

/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js version: 0.5.2
* json-patch-duplex.js version: 0.5.3
* (c) 2013 Joachim Wester

@@ -5,0 +5,0 @@ * MIT license

{
"name": "fast-json-patch",
"version": "0.5.2",
"version": "0.5.3",
"description": "Fast implementation of JSON-Patch (RFC-6902) with duplex (observe changes) capabilities",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/Starcounter-Jack/JSON-Patch",

@@ -73,2 +73,3 @@ JSON-Patch

Applying patches:
```js

@@ -85,2 +86,3 @@ var myobj = { firstName:"Albert", contactDetails: { phoneNumbers: [ ] } };

Generating patches:
```js

@@ -99,2 +101,3 @@ var myobj = { firstName:"Joachim", lastName:"Wester", contactDetails: { phoneNumbers: [ { number:"555-123" }] } };

Comparing two object trees:
```js

@@ -108,2 +111,3 @@ var objA = {user: {firstName: "Albert", lastName: "Einstein"}};

Validating a sequence of patches:
```js

@@ -117,3 +121,3 @@ var obj = {user: {firstName: "Albert"}};

else {
for (var i=0; i<errors.length; i++) {
for (var i=0; i < errors.length; i++) {
if (!errors[i]) {

@@ -226,3 +230,4 @@ console.log("Valid patch at index", i, patches[i]);

OPERATION_FROM_REQUIRED | Operation `from` property is not present (applicable in `move` and `copy` operations)
OPERATION_VALUE_REQUIRED | Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)
OPERATION_VALUE_REQUIRED | Operation `value` property is not present, or `undefined` (applicable in `add`, `replace` and `test` operations)
OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED | Operation `value` property object has at least one `undefined` value (applicable in `add`, `replace` and `test` operations)
OPERATION_PATH_CANNOT_ADD | Cannot perform an `add` operation at the desired path

@@ -234,4 +239,18 @@ OPERATION_PATH_UNRESOLVABLE | Cannot perform the operation at a path that does not exist

## `undefined`s (JSON to JS extension)
As `undefined` is not a valid value for any JSON node, it's also not valid value o JSON Patch operation object value property. Therefore, for valid JSON document, `jsonpatch` will not generate JSON Patches that sets anything to `undefined`.
However, to play nicer with natural JavaScipt objects `jsonpatch` can be applied to an object that contains `undefined`, in such case we will treat it as JS does. `.apply` will handle JSON Patches with `value: undefined` as any other falsy value. `.generate`, `.compare`, `.observe` methods will also produce JSON Patches with `undefined`s, but only for (non valid) JSON documents that contains it.
## :no_entry_sign: `undefined`s (JS to JSON projection)
~~As `undefined` is not a valid value for any JSON node, it's also not valid value o JSON Patch operation object value property. Therefore `jsonpatch` will not generate JSON Patches that sets anything to `undefined`.~~
~~However, to play nicer with natural JavaScipt objects `jsonpatch` can be applied to an object that contains `undefined`, in such case we will use it as native `JSON.stringify` - we will treat them as non-existing nodes, and map to `null` for array elements.~~
## Changelog
To see the list of recent changes, see [Releases](https://github.com/Starcounter-Jack/JSON-Patch/releases).
/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js version: 0.5.2
* json-patch-duplex.js version: 0.5.3
* (c) 2013 Joachim Wester

@@ -335,19 +335,3 @@ * MIT license

if (!(arr[a].name === 'length' && _isArray(arr[a].object)) && !(arr[a].name === '__Jasmine_been_here_before__')) {
var type = arr[a].type;
switch (type) {
case 'new':
type = 'add';
break;
case 'deleted':
type = 'delete';
break;
case 'updated':
type = 'update';
break;
}
observeOps[type].call(arr[a], patches, getPath(root, arr[a].object));
observeOps[arr[a].type].call(arr[a], patches, getPath(root, arr[a].object));
}

@@ -633,2 +617,21 @@ a++;

/**
* Recursively checks whether an object has any undefined values inside.
*/
function hasUndefined(obj) {
if (obj === undefined) {
return true;
}
if (typeof obj == "array" || typeof obj == "object") {
for (var i in obj) {
if (hasUndefined(obj[i])) {
return true;
}
}
}
return false;
}
/**
* Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.

@@ -651,2 +654,4 @@ * @param {object} operation - operation object (patch)

throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_REQUIRED', index, operation, tree);
} else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && hasUndefined(operation.value)) {
throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED', index, operation, tree);
} else if (tree) {

@@ -653,0 +658,0 @@ if (operation.op == "add") {

/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js version: 0.5.2
* json-patch-duplex.js version: 0.5.3
* (c) 2013 Joachim Wester

@@ -345,21 +345,3 @@ * MIT license

) {
var type = arr[a].type;
//old record type names before 10/29/2013 (http://wiki.ecmascript.org/doku.php?id=harmony:observe)
//this block can be removed when Chrome 33 stable is released
switch(type) {
case 'new':
type = 'add';
break;
case 'deleted':
type = 'delete';
break;
case 'updated':
type = 'update';
break;
}
observeOps[type].call(arr[a], patches, getPath(root, arr[a].object));
observeOps[arr[a].type].call(arr[a], patches, getPath(root, arr[a].object));
}

@@ -655,2 +637,21 @@ a++;

/**
* Recursively checks whether an object has any undefined values inside.
*/
export function hasUndefined(obj:any): boolean {
if (obj === undefined) {
return true;
}
if (typeof obj == "array" || typeof obj == "object") {
for (var i in obj) {
if (hasUndefined(obj[i])) {
return true;
}
}
}
return false;
}
/**

@@ -684,2 +685,6 @@ * Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.

else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && hasUndefined(operation.value)) {
throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED', index, operation, tree);
}
else if (tree) {

@@ -686,0 +691,0 @@ if (operation.op == "add") {

/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js version: 0.5.2
* json-patch-duplex.js version: 0.5.3
* (c) 2013 Joachim Wester

@@ -293,2 +293,21 @@ * MIT license

/**
* Recursively checks whether an object has any undefined values inside.
*/
function hasUndefined(obj) {
if (obj === undefined) {
return true;
}
if (typeof obj == "array" || typeof obj == "object") {
for (var i in obj) {
if (hasUndefined(obj[i])) {
return true;
}
}
}
return false;
}
/**
* Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.

@@ -311,2 +330,4 @@ * @param {object} operation - operation object (patch)

throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_REQUIRED', index, operation, tree);
} else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && hasUndefined(operation.value)) {
throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED', index, operation, tree);
} else if (tree) {

@@ -313,0 +334,0 @@ if (operation.op == "add") {

/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js version: 0.5.2
* json-patch-duplex.js version: 0.5.3
* (c) 2013 Joachim Wester

@@ -293,2 +293,21 @@ * MIT license

/**
* Recursively checks whether an object has any undefined values inside.
*/
export function hasUndefined(obj:any): boolean {
if (obj === undefined) {
return true;
}
if (typeof obj == "array" || typeof obj == "object") {
for (var i in obj) {
if (hasUndefined(obj[i])) {
return true;
}
}
}
return false;
}
/**

@@ -322,2 +341,6 @@ * Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.

else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && hasUndefined(operation.value)) {
throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED', index, operation, tree);
}
else if (tree) {

@@ -324,0 +347,0 @@ if (operation.op == "add") {

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