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

@zerodep/is-equal

v2.0.7

Published

A utility to compare two values of any type for equality by value

Downloads

17

Readme

@zerodep/is-equal

version language types license

CodeFactor Known Vulnerabilities

A performant utility to compare two values for equality by value (not by reference). This means JSON objects with the same key:value pairs will be deemed equal as will arrays with identical items even if in different order.

Full documentation is available at the zerodep.app page.

Examples

All @zerodep packages support both ESM and CJS.

import { isEqual } from '@zerodep/is-equal';
// or
const { isEqual } = require('@zerodep/is-equal');

Multiple Cases

// strings
isEqual('abc', 'abc'); // true
isEqual('abc', 'def'); // false
isEqual('', ''); // true
isEqual('G', new String('G')); // true

// integers
isEqual(42, 42); // true
isEqual(42, 12); // false
isEqual(2161, new Number(2161)); // true
isEqual(0, -0); // false

// floats
isEqual(3.141592653589793, 3.141592653589793); // true
isEqual(-273.15, new Number(-273.15)); // true

// number-like
isEqual(Math.NaN, Math.NaN); // true
isEqual(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY); // true

// booleans
isEqual(false, false); // true
isEqual(true, new Boolean(true)); // true

// bigint
isEqual(-20n, -20n); // true
isEqual(8675309n, BigInt(8675309)); // true

// nothing
isEqual(null, null); // true
isEqual(undefined, undefined); // true

// arrays (even if deeply nested)
isEqual([], []); // true
isEqual([1, 2], [1, 2]); // true
isEqual([6], [7]); // false
isEqual(['b', [2, 4, ['c', 'd', 6]]], [[4, ['c', 'd', 6], 2], 'b']); // true

// objects (even if deeply nested)
isEqual({}, {}); // true
isEqual({ c: 3, d: 4 }, { c: 3, d: 4, e: 5 }); // false
isEqual({ g: 5, h: { i: [1, 2, 3], j: ['a', 'b', 'c'] } }, { h: { j: ['a', 'b', 'c'], i: [1, 2, 3] }, g: 5 }); // true

// dates
isEqual(new Date('2000-01-01T00:00:00.000Z'), new Date('2000-01-01T00:00:00.000Z')); // true

// errors
isEqual(new Error('error 2'), new Error('error 2')); // true
isEqual(new TypeError('error'), new RangeError('error')); // false

// functions
isEqual(() => {}, () => {}); // true
isEqual(() => 'a', () => 'b'); // false

// maps
isEqual(new Map([]), new Map()); // true
isEqual(new Map([['d', 4]]), new Map([['e', 5]]); // false

isEqual(new Set([]), new Set([])); // true
isEqual(new Set([1, 2, 3]), new Set([1, 2, 3])); // true

// regex
isEqual(/\d+/g, /\d+/g); // true
isEqual(/[0-9]+/g, /[\d]+/g); // false

// array buffers
isEqual(new ArrayBuffer(12), new ArrayBuffer(12)); // true
isEqual(new ArrayBuffer(32), new ArrayBuffer(16)); // false

// typed arrays
isEqual(Int8Array.from([2]), Int8Array.from([2])); // true
isEqual(Uint8Array.from([3]), Uint8Array.from([4])); // false

// incomparables
isEqual(new WeakMap(), new WeakMap()); // throws ZeroDepError: Cannot compare WeakMap values
isEqual(new WeakSet(), new WeakSet()); // throws ZeroDepError: Cannot compare WeakSet values
isEqual(Symbol(), Symbol()); // throws ZeroDepError: Cannot compare Symbol values