GithubHelp home page GithubHelp logo

isabella232 / equals Goto Github PK

View Code? Open in Web Editor NEW

This project forked from segmentio/equals

0.0 0.0 0.0 56 KB

Check if two values are deeply equivalent

License: MIT License

JavaScript 93.57% Makefile 2.78% HTML 3.65%

equals's Introduction

equals

compare values of any type for equility

Installation

With your favorite package manager:

  • packin: packin add equals
  • component: component install jkroso/equals
  • npm: npm install equals

then in your app:

var equal = require('equals')

API

equal(a, b, [memos])

equal takes as many arguments as you like of any type you like and returns a boolean result. Primitive types are equal if they are ===. While composite types, i.e. Objects and Arrays, are considered equal if they have both the same structure and each sub-value is also equal. Circular references in composite structures are supported.

Same structure:

equal(
  { a : [ 2, 3 ], b : [ 4 ] },
  { a : [ 2, 3 ], b : [ 4 ] }
) // => true

Different Structure:

equal(
  { x : 5, y : [6] },
  { x : 5}
) // => false

Same structure, different values:

equal(
  { a: [ 1, 2 ], b : [ 4 ]},
  { a: [ 2, 3 ], b : [ 4 ]}
) // => false

Primitives:

equal(new Date(0), new Date(1)) // => false

Some possible gotchas:

  • null is not equal to undefined.
  • NaN is equal to NaN (normally not the case).
  • -0 is equal to +0.
  • Strings will not coerce to numbers.
  • Non enumerable properties will not be checked. They can't be.
  • arguments.callee is not considered when comparing arguments

equals's People

Contributors

jkroso avatar anthonyshort avatar ianstormtaylor avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.