Socket
Socket
Sign inDemoInstall

json-diff

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-diff - npm Package Compare versions

Comparing version 0.9.0 to 0.9.1

4

lib/cli.js

@@ -77,2 +77,3 @@ const fs = require('fs')

}
process.exit(1)
} else {

@@ -82,4 +83,5 @@ if (options.verbose) {

}
process.exit(0)
}
process.exit(0)
}

@@ -9,3 +9,3 @@ {

"description": "JSON diff",
"version": "0.9.0",
"version": "0.9.1",
"homepage": "https://github.com/andreyvit/json-diff",

@@ -30,4 +30,4 @@ "license": "MIT",

"coffeescript": "^2.6.1",
"eslint": "^8.4.1",
"eslint-config-standard": "^16.0.3",
"eslint": "^8",
"eslint-config-standard": "^17",
"mocha": "9.1.3",

@@ -34,0 +34,0 @@ "jscoverage": "^0.6.0"

@@ -169,121 +169,150 @@ JSON structural diff

colorizeToArray
✔ should return ' <value>' for a scalar value
✔ should return ' <value>' for 'null' value
✔ should return ' <value>' for 'false' value
✔ should return '-<old value>', '+<new value>' for a scalar diff
✔ should return '-<old value>', '+<new value>' for 'null' and 'false' diff
✔ should return '-<removed key>: <removed value>' for an object diff with a removed key
✔ should return '+<added key>: <added value>' for an object diff with an added key
✔ should return '+<added key>: <added value>' for an object diff with an added key with 'null' value
✔ should return '+<added key>: <added value>' for an object diff with an added key with 'false' value
✔ should return '+<added key>: <added stringified value>' for an object diff with an added key and a non-scalar value
✔ should return ' <modified key>: <colorized diff>' for an object diff with a modified key
✔ should return '+<inserted item>' for an array diff
✔ should return '-<deleted item>' for an array diff
✔ should handle an array diff with subobject diff
colorizeToArray
✔ should return ' <value>' for a scalar value
✔ should return ' <value>' for 'null' value
✔ should return ' <value>' for 'false' value
✔ should return '-<old value>', '+<new value>' for a scalar diff
✔ should return '-<old value>', '+<new value>' for 'null' and 'false' diff
✔ should return '-<removed key>: <removed value>' for an object diff with a removed key
✔ should return '+<added key>: <added value>' for an object diff with an added key
✔ should return '+<added key>: <added value>' for an object diff with an added key with 'null' value
✔ should return '+<added key>: <added value>' for an object diff with an added key with 'false' value
✔ should return '+<added key>: <added stringified value>' for an object diff with an added key and a non-scalar value
✔ should return ' <modified key>: <colorized diff>' for an object diff with a modified key
✔ should return '+<inserted item>' for an array diff
✔ should return '-<deleted item>' for an array diff
✔ should handle an array diff with subobject diff
✔ should collapse long sequences of identical subobjects into one '...'
colorize
✔ should return a string with ANSI escapes
✔ should return a string without ANSI escapes on { color: false }
colorize
✔ should return a string with ANSI escapes
✔ should return a string without ANSI escapes on { color: false }
diff
with simple scalar values
✔ should return undefined for two identical numbers
✔ should return undefined for two identical strings
✔ should return { __old: <old value>, __new: <new value> } object for two different numbers
with objects
✔ should return undefined for two empty objects
✔ should return undefined for two objects with identical contents
✔ should return undefined for two object hierarchies with identical contents
✔ should return { <key>__deleted: <old value> } when the second object is missing a key
✔ should return { <key>__added: <new value> } when the first object is missing a key
✔ should return { <key>: { __old: <old value>, __new: <new value> } } for two objects with different scalar values for a key
✔ should return { <key>: <diff> } with a recursive diff for two objects with different values for a key
with arrays of scalars
✔ should return undefined for two arrays with identical contents
✔ should return [..., ['-', <removed item>], ...] for two arrays when the second array is missing a value
✔ should return [..., ['+', <added item>], ...] for two arrays when the second one has an extra value
✔ should return [..., ['+', <added item>]] for two arrays when the second one has an extra value at the end (edge case test)
with arrays of objects
✔ should return undefined for two arrays with identical contents
✔ should return undefined for two arrays with identical, empty object contents
✔ should return undefined for two arrays with identical, empty array contents
✔ should return undefined for two arrays with identical array contents including 'null'
✔ should return undefined for two arrays with identical, repeated contents
✔ should return [..., ['-', <removed item>], ...] for two arrays when the second array is missing a value
✔ should return [..., ['+', <added item>], ...] for two arrays when the second array has an extra value
✔ should return [['+', <added item>], ..., ['+', <added item>]] for two arrays containing objects of 3 or more properties when the second array has extra values (fixes issue #57)
✔ should return [..., ['+', <added item>], ...] for two arrays when the second array has a new but nearly identical object added
✔ should return [..., ['~', <diff>], ...] for two arrays when an item has been modified
diff
with simple scalar values
✔ should return undefined for two identical numbers
✔ should return undefined for two identical strings
✔ should return { __old: <old value>, __new: <new value> } object for two different numbers
with objects
✔ should return undefined for two empty objects
✔ should return undefined for two objects with identical contents
✔ should return undefined for two object hierarchies with identical contents
✔ should return { <key>__deleted: <old value> } when the second object is missing a key
✔ should return { <key>__added: <new value> } when the first object is missing a key
✔ should return { <key>: { __old: <old value>, __new: <new value> } } for two objects with different scalar values for a key
✔ should return { <key>: <diff> } with a recursive diff for two objects with different values for a key
with arrays of scalars
✔ should return undefined for two arrays with identical contents
✔ should return [..., ['-', <removed item>], ...] for two arrays when the second array is missing a value
✔ should return [..., ['+', <added item>], ...] for two arrays when the second one has an extra value
✔ should return [..., ['+', <added item>]] for two arrays when the second one has an extra value at the end (edge case test)
with arrays of objects
✔ should return undefined for two arrays with identical contents
✔ should return undefined for two arrays with identical, empty object contents
✔ should return undefined for two arrays with identical, empty array contents
✔ should return undefined for two arrays with identical array contents including 'null'
✔ should return undefined for two arrays with identical, repeated contents
✔ should return [..., ['-', <removed item>], ...] for two arrays when the second array is missing a value
✔ should return [..., ['+', <added item>], ...] for two arrays when the second array has an extra value
✔ should return [['+', <added item>], ..., ['+', <added item>]] for two arrays containing objects of 3 or more properties when the second array has extra values (fixes issue #57)
✔ should return [..., ['+', <added item>], ...] for two arrays when the second array has a new but nearly identical object added
✔ should return [..., ['~', <diff>], ...] for two arrays when an item has been modified
with reported bugs
✔ should handle type mismatch during scalarize
✔ should handle mixed scalars and non-scalars in scalarize
diff({full: true})
with simple scalar values
✔ should return the number for two identical numbers
✔ should return the string for two identical strings
✔ should return { __old: <old value>, __new: <new value> } object for two different numbers
with objects
✔ should return an empty object for two empty objects
✔ should return the object for two objects with identical contents
✔ should return the object for two object hierarchies with identical contents
✔ should return { <key>__deleted: <old value>, <remaining properties>} when the second object is missing a key
✔ should return { <key>__added: <new value>, <remaining properties> } when the first object is missing a key
✔ should return { <key>: { __old: <old value>, __new: <new value> } } for two objects with different scalar values for a key
✔ should return { <key>: <diff>, <equal properties> } with a recursive diff for two objects with different values for a key
✔ should return { <key>: <diff>, <equal properties> } with a recursive diff for two objects with different values for a key
with arrays of scalars
✔ should return an array showing no changes for any element for two arrays with identical contents
✔ should return [[' ', <unchanged item>], ['-', <removed item>], [' ', <unchanged item>]] for two arrays when the second array is missing a value
✔ should return [' ', <unchanged item>], ['+', <added item>], [' ', <unchanged item>]] for two arrays when the second one has an extra value
✔ should return [' ', <unchanged item>s], ['+', <added item>]] for two arrays when the second one has an extra value at the end (edge case test)
with arrays of objects
✔ should return an array of unchanged elements for two arrays with identical contents
✔ should return an array with an unchanged element for two arrays with identical, empty object contents
✔ should return an array with an unchanged element for two arrays with identical, empty array contents
✔ should return an array of unchanged elements for two arrays with identical array contents including 'null'
✔ should return an array of unchanged elements for two arrays with identical, repeated contents
✔ should return [[' ', <unchanged item>], ['-', <removed item>], [' ', <unchanged item>]] for two arrays when the second array is missing a value
✔ should return [[' ', <unchanged item>], ['+', <added item>], [' ', <unchanged item>]] for two arrays when the second array has an extra value
✔ should return [[' ', <unchanged item>], ['+', <added item>], [' ', <unchanged item>]] for two arrays when the second array has a new but nearly identical object added
✔ should return [[' ', <unchanged item>], ['~', <diff>], [' ', <unchanged item>]] for two arrays when an item has been modified
diff({sort: true})
with arrays
✔ should return undefined for two arrays with the same contents in different order
diff({keysOnly: true})
with simple scalar values
✔ should return undefined for two identical numbers
✔ should return undefined for two identical strings
✔ should return undefined object for two different numbers
with objects
✔ should return undefined for two empty objects
✔ should return undefined for two objects with identical contents
✔ should return undefined for two object hierarchies with identical contents
✔ should return { <key>__deleted: <old value> } when the second object is missing a key
✔ should return { <key>__added: <new value> } when the first object is missing a key
✔ should return undefined for two objects with different scalar values for a key
✔ should return undefined with a recursive diff for two objects with different values for a key
✔ should return { <key>: <diff> } with a recursive diff when second object is missing a key and two objects with different values for a key
with arrays of scalars
✔ should return undefined for two arrays with identical contents
✔ should return undefined for two arrays with when an item has been modified
✔ should return [..., ['-', <removed item>], ...] for two arrays when the second array is missing a value
✔ should return [..., ['+', <added item>], ...] for two arrays when the second one has an extra value
✔ should return [..., ['+', <added item>]] for two arrays when the second one has an extra value at the end (edge case test)
with arrays of objects
✔ should return undefined for two arrays with identical contents
✔ should return undefined for two arrays with identical, empty object contents
✔ should return undefined for two arrays with identical, empty array contents
✔ should return undefined for two arrays with identical, repeated contents
✔ should return [..., ['-', <removed item>], ...] for two arrays when the second array is missing a value
✔ should return [..., ['+', <added item>], ...] for two arrays when the second array has an extra value
✔ should return [..., ['~', <diff>], ...] for two arrays when an item has been modified
diff({keepUnchangedValues: true})
with nested object
✔ should return partial object with modified and unmodified elements in the edited scope
diffString
✔ should produce the expected result for the example JSON files
✔ should produce the expected colored result for the example JSON files
✔ return an empty string when no diff found
diff({full: true})
with simple scalar values
✔ should return the number for two identical numbers
✔ should return the string for two identical strings
✔ should return { __old: <old value>, __new: <new value> } object for two different numbers
with objects
✔ should return an empty object for two empty objects
✔ should return the object for two objects with identical contents
✔ should return the object for two object hierarchies with identical contents
✔ should return { <key>__deleted: <old value>, <remaining properties>} when the second object is missing a key
✔ should return { <key>__added: <new value>, <remaining properties> } when the first object is missing a key
✔ should return { <key>: { __old: <old value>, __new: <new value> } } for two objects with different scalar values for a key
✔ should return { <key>: <diff>, <equal properties> } with a recursive diff for two objects with different values for a key
✔ should return { <key>: <diff>, <equal properties> } with a recursive diff for two objects with different values for a key
with arrays of scalars
✔ should return an array showing no changes for any element for two arrays with identical contents
✔ should return [[' ', <unchanged item>], ['-', <removed item>], [' ', <unchanged item>]] for two arrays when the second array is missing a value
✔ should return [' ', <unchanged item>], ['+', <added item>], [' ', <unchanged item>]] for two arrays when the second one has an extra value
✔ should return [' ', <unchanged item>s], ['+', <added item>]] for two arrays when the second one has an extra value at the end (edge case test)
with arrays of objects
✔ should return an array of unchanged elements for two arrays with identical contents
✔ should return an array with an unchanged element for two arrays with identical, empty object contents
✔ should return an array with an unchanged element for two arrays with identical, empty array contents
✔ should return an array of unchanged elements for two arrays with identical array contents including 'null'
✔ should return an array of unchanged elements for two arrays with identical, repeated contents
✔ should return [[' ', <unchanged item>], ['-', <removed item>], [' ', <unchanged item>]] for two arrays when the second array is missing a value
✔ should return [[' ', <unchanged item>], ['+', <added item>], [' ', <unchanged item>]] for two arrays when the second array has an extra value
✔ should return [[' ', <unchanged item>], ['+', <added item>], [' ', <unchanged item>]] for two arrays when the second array has a new but nearly identical object added
✔ should return [[' ', <unchanged item>], ['~', <diff>], [' ', <unchanged item>]] for two arrays when an item has been modified
diff({ outputKeys: foo,bar }
✔ should return keys foo and bar although they have no changes
✔ should return keys foo (with addition) and bar (with no changes)
✔ should return keys foo and bar (with addition)
✔ should return nothing as the entire object is equal, no matter that show keys has some of them
✔ should return the keys of an entire object although it has no changes
90 passing (42ms)
diff({keysOnly: true})
with simple scalar values
✔ should return undefined for two identical numbers
✔ should return undefined for two identical strings
✔ should return undefined object for two different numbers
with objects
✔ should return undefined for two empty objects
✔ should return undefined for two objects with identical contents
✔ should return undefined for two object hierarchies with identical contents
✔ should return { <key>__deleted: <old value> } when the second object is missing a key
✔ should return { <key>__added: <new value> } when the first object is missing a key
✔ should return undefined for two objects with different scalar values for a key
✔ should return undefined with a recursive diff for two objects with different values for a key
✔ should return { <key>: <diff> } with a recursive diff when second object is missing a key and two objects with different values for a key
with arrays of scalars
✔ should return undefined for two arrays with identical contents
✔ should return undefined for two arrays with when an item has been modified
✔ should return [..., ['-', <removed item>], ...] for two arrays when the second array is missing a value
✔ should return [..., ['+', <added item>], ...] for two arrays when the second one has an extra value
✔ should return [..., ['+', <added item>]] for two arrays when the second one has an extra value at the end (edge case test)
with arrays of objects
✔ should return undefined for two arrays with identical contents
✔ should return undefined for two arrays with identical, empty object contents
✔ should return undefined for two arrays with identical, empty array contents
✔ should return undefined for two arrays with identical, repeated contents
✔ should return [..., ['-', <removed item>], ...] for two arrays when the second array is missing a value
✔ should return [..., ['+', <added item>], ...] for two arrays when the second array has an extra value
✔ should return [..., ['~', <diff>], ...] for two arrays when an item has been modified
diffString
✔ should produce the expected result for the example JSON files
✔ should produce the expected result for the example JSON files with precision set to 1
✔ should produce the expected colored result for the example JSON files
✔ return an empty string when no diff found
diff({ outputNewOnly: true }
✔ should return only new diffs (added)
✔ should return only new diffs (changed)
✔ should return only new diffs (deleted)
✔ should return only old diffs - exchanged first and second json (added)
✔ should return only old diffs - exchanged first and second json (changed)
✔ should return only old diffs - exchanged first and second json (deleted)
107 passing (74ms)
Change Log
----------
* 0.9.1 Fix bug #88
* 0.9.0 Add --output-new-only option

@@ -290,0 +319,0 @@ * 0.8.0 Add --keep-unchanged-values option

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