JSPM

node-json-equal

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 213
  • Score
    100M100P100Q69846F
  • License MIT

Recursively checks deep equality between two JSON-like objects (order of array oblivious).

Package Exports

  • node-json-equal

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-json-equal) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

node-json-equal

Determine deep equality between JSON-like JavaScript objects. Using opts, you can compare two arrays irrespective of the ordering of elements. This module is largely inspired by deep-equal.

Another inspiration is this javascript blog on the typeof keyword

Installation

npm install node-json-equal

Usage

    var equal = require('node-json-equal');

    equal (a, b, opts);

    // Array order aware
    equal (
        [ { a: 1, b: 'first '}, { c: 'second', d: null } ],
        [ { b: 'first', a: 1}, { d: null,  c: 'second'} ]
    ); // true

   
    // Array order unaware
    equal (
        [ { c: 'second', d: null }, { a: 1, b: 'first'} ],
        [ { b: 'first', a: 1}, { d: null,  c: 'second'} ],
        { arrayOrder: false }
    ); // true

    // Array order unaware
    equal (
        [ { c: 'second', d: undefined }, { a: 1, b: 'first'} ],
        [ { b: 'first', a: 1}, { d: null,  c: 'second'} ],
        { arrayOrder: false }
    ); // false

For more examples, check out tests

Options

    var options = {
            arrayOrder: false // Defaults to true. If set to false, will test equality irrespective of the order of elements inside the array
    };

    equal( [1, 2, 3, 4], [4, 3, 1, 2], options); // true

Tests

npm test

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style.
Add unit tests for any new or changed functionality. Lint and test your code.

License

MIT

Release History

  • 0.1.0 Initial Release