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

go-equality

v1.0.4

Published

Equality checking functions that work for both primitive types and objects, including nested objects and cyclic objects with a circular reference.

Downloads

218

Readme

Go Equality

Equality checking functions that work for both primitive types and objects, including nested objects and cyclic objects with a circular reference.

codecov.io Code Coverage jsdoc donation

  • version: 1.0.4
  • license: GNU LGPLv3

Installation

npm i go-equality

or

yarn add go-equality

Usage

ES6

import { isEqual } from 'go-equality'

isEqual([1, 2, 3], [1, 2, 3]); // => true

Node

const { isEqual } = require('go-equality');

isEqual([1, 2, 3], [1, 2, 3]); // => true

Web browser

<script src="dist/go-equality.min.js"></script>
<script>
    const { isEqual } = Equality;

	isEqual([1, 2, 3], [1, 2, 3]); // => true
</script>

Documentation

Table of Contents

isEqual

Determines whether two values are equal.

Two values are considered equal if they are:

  • Primitive values whose types and values are the same
  • Identical objects (comparing against itself)
  • One of them is a primitive wrapper object whose value is the same as the other value
  • Objects that have the same property names and equal values (including non-enumerable properties)
  • Objects that have the equals method and both return true when tested against each other
  • NaN values

These values are considered not equal:

  • Primitive values whose types or values are different
  • Objects that have a different constructor or property name or value (including non-enumerable properties)
  • One of the objects has the equals method and it returns false when tested against the other value
  • Functions
  • Symbol values

Parameters

  • value any The value to compare
  • other any The other value to compare with

Examples

Equal values

// returns true
isEqual(1, 1);
isEqual(1, new Number(1));
isEqual([1, 2, 3], [1, 2, 3]);
isEqual({name: "foo", value: 10}, {value: 10, name: "foo"});
isEqual(NaN, NaN);

Not equal values

// returns false
isEqual(1, "1");
isEqual(null, undefined);
isEqual({}, {a: undefined});
isEqual([1, 2, 3], [2, 3, 1]);
isEqual(function() {}, function() {});
isEqual(Symbol("abc"), Symbol("abc"));

Returns boolean true if the two values are considered equal; false otherwise.

Meta

  • since: 1.0.0

isLooseEqual

Determines whether two values are loosely equal.

Two values are considered loosely equal if they are:

  • Primitive values whose types are the same or compatible and the values are equal (after conversion if required)
  • Identical objects (comparing against itself)
  • One of them is a primitive wrapper object whose value is the same as the other value
  • Objects that have the same property names and loosely equal values (including non-enumerable properties)
  • Objects that have the equals method and both return true when tested against each other
  • NaN values

These values are considered not equal:

  • Primitive values whose types are not compatible or values are different
  • Objects that have a different property name or value (including non-enumerable properties)
  • One of the objects has the equals method and it returns false when tested against the other value
  • Functions
  • Symbol values

Parameters

  • value any The value to compare
  • other any The other value to compare with

Examples

Equal values

// returns true
isLooseEqual(null, undefined);
isLooseEqual(1, "1");
isLooseEqual(1, new Number(1));
isLooseEqual(1, BigInt(1));
isLooseEqual(1, true);
isLooseEqual(NaN, NaN);

Not equal values

// returns false
isLooseEqual(true, "true");
isLooseEqual(false, undefined);
isLooseEqual({}, {a: undefined});
isLooseEqual("abc", ["a", "b", "c"]);
isLooseEqual([1, 2, 3], [2, 3, 1]);
isLooseEqual(function() {}, function() {});
isLooseEqual(Symbol("abc"), Symbol("abc"));

Returns boolean true if the two values are loosely equal; false otherwise.

Meta

  • since: 1.0.0

isStrictEqual

Determines whether two values are strictly equal.

Two values are considered strictly equal if they are:

  • Primitive values whose types and values are the same
  • Identical objects (comparing against itself)
  • Objects that have the equals method and both return true when tested against each other
  • Objects that have the same constructor and the same property names and values (including non-enumerable properties)
  • Primitive NaN values or Number objects that represent NaN

These values are considered not equal:

  • Primitive values whose types or values are different
  • Objects that have a different constructor or property name or value (including non-enumerable properties)
  • One of the objects has the equals method and it returns false when tested against the other value
  • Functions
  • Symbol values

Parameters

  • value any The value to compare
  • other any The other value to compare with

Examples

Equal values

// returns true
isStrictEqual(1, 1);
isStrictEqual([1, 2, 3], [1, 2, 3]);
isStrictEqual({name: "foo", value: 10}, {value: 10, name: "foo"});
isStrictEqual(NaN, NaN);

Not equal values

// returns false
isStrictEqual(1, "1");
isStrictEqual(1, new Number(1));
isStrictEqual(null, undefined);
isStrictEqual({}, {a: undefined});
isStrictEqual(function() {}, function() {});
isStrictEqual(Symbol("abc"), Symbol("abc"));

Returns boolean true if the two values are strictly equal; false otherwise.

Meta

  • since: 1.0.0