npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nested-equal

v1.0.1

Published

A tiny (~200B) and fast nested/deep equality utility

Downloads

361

Readme

nested-equal Check Coverage

A tiny (~239B) and super fast deep/nested equality utility.

Takes 2 values and returns a boolean indicating if they are equal or not by traversing recursively. Supports Objects, Arrays, Numbers, Strings, null, undefined, NaN, Functions. Other types like Map, Set, Date and others use reference equality instead of value equality.

Key order within objects does not matter while value order within arrays does matter.

Installation

$ npm install nested-equal 

Usage

import { nestedEqual } from "nested-equal";

nestedEqual({},{}); // true
nestedEqual({a:1},{a:1}); // true
nestedEqual([1,2],[1,3]); // false 
nestedEqual(NaN,NaN); // true 
nestedEqual([1,2,3],[1,2,3]); // true 
nestedEqual([
  {a:'value',b:'value'},
  {a:'value',b:'value'},
],[
  {a:'value',b:'value'},
  {a:'value',b:'value'},
]) // true
nestedEqual(5,'5'); // false
nestedEqual(null,null); // true 
nestedEqual(null,undefined); // false 

Benchmarks

Claiming a library is fast without looking into the data structure is naive at best, since the data structure largely impacts performance as no algorithm can handle all the different data structures. Hence a couple of benchmarks were made with some different data structures to compare it to other popular libararies.

Benchmark 1
  lodash.isequal               x 66,593 ops/sec ±0.43% (92 runs sampled)
  deep-equal                   x 772 ops/sec ±4.45% (43 runs sampled)
  nested-equal                 x 458,818 ops/sec ±0.40% (91 runs sampled)
  dequal                       x 431,045 ops/sec ±0.23% (95 runs sampled)
  nano-equal                   x 284,753 ops/sec ±0.37% (89 runs sampled)

Benchmark 2
  lodash.isequal               x 853,636 ops/sec ±0.67% (91 runs sampled)
  deep-equal                   x 2,172 ops/sec ±1.83% (75 runs sampled)
  nested-equal                 x 6,034,107 ops/sec ±0.72% (93 runs sampled)
  dequal                       x 5,302,918 ops/sec ±0.70% (95 runs sampled)
  nano-equal                   x 3,542,214 ops/sec ±0.24% (93 runs sampled)

Benchmark 3
  lodash.isequal               x 14,347,632 ops/sec ±0.89% (91 runs sampled)
  deep-equal                   x 4,502 ops/sec ±1.76% (72 runs sampled)
  nested-equal                 x 21,252,686 ops/sec ±0.31% (93 runs sampled)
  dequal                       x 21,489,939 ops/sec ±0.32% (94 runs sampled)
  nano-equal                   x 28,915,716 ops/sec ±0.49% (94 runs sampled)

Benchmark 4
  lodash.isequal               x 63,600 ops/sec ±1.16% (64 runs sampled)
  deep-equal                   x 1,420 ops/sec ±0.64% (88 runs sampled)
  nested-equal                 x 2,909,724 ops/sec ±0.22% (91 runs sampled)
  dequal                       x 4,138,053 ops/sec ±0.25% (94 runs sampled)
  nano-equal                   x 1,662,534 ops/sec ±2.92% (90 runs sampled)

Benchmark 5
  lodash.isequal               x 70,076 ops/sec ±0.93% (90 runs sampled)
  deep-equal                   x 2,113 ops/sec ±0.54% (88 runs sampled)
  nested-equal                 x 7,432,844 ops/sec ±0.22% (93 runs sampled)
  dequal                       x 7,161,662 ops/sec ±0.61% (94 runs sampled)
  nano-equal                   x 4,496,048 ops/sec ±0.59% (94 runs sampled)

Running on Node.js v12.13.0, 64-bit OS, Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz, 16.0 GB RAM

API

nestedEqual(value1:any,value2:any)

Returns: Boolean

Returns true or false indicating if the two values are equal or not.