value-equal
Are these two JavaScript values equal?
Last updated 10 months ago by mjackson .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install value-equal 
SYNC missed versions from official npm registry.

value-equal Travis npm package

value-equal determines if two JavaScript values are equal using Object.prototype.valueOf.

In many instances when I'm checking for object equality, what I really want to know is if their values are equal. This is good for:

  • Stuff you keep in localStorage
  • window.history.state values
  • Query strings

Installation

Using npm:

$ npm install --save value-equal

Then with a module bundler like webpack, use as you would anything else:

// using ES6 modules
import valueEqual from 'value-equal';

// using CommonJS modules
var valueEqual = require('value-equal');

The UMD build is also available on unpkg:

<script src="https://unpkg.com/value-equal"></script>

You can find the library on window.valueEqual.

Usage

valueEqual(1, 1); // true
valueEqual('asdf', 'asdf'); // true
valueEqual('asdf', new String('asdf')); // true
valueEqual(true, true); // true
valueEqual(true, false); // false
valueEqual({ a: 'a' }, { a: 'a' }); // true
valueEqual({ a: 'a' }, { a: 'b' }); // false
valueEqual([1, 2, 3], [1, 2, 3]); // true
valueEqual([1, 2, 3], [2, 3, 4]); // false

That's it. Enjoy!

Current Tags

  • 1.0.1                                ...           latest (10 months ago)
  • 0.4.1-beta.6                                ...           next (10 months ago)

16 Versions

  • 1.0.1                                ...           10 months ago
  • 1.0.0                                ...           10 months ago
  • 0.5.3                                ...           10 months ago
  • 0.5.1                                ...           10 months ago
  • 0.5.0                                ...           10 months ago
  • 0.4.1-beta.6                                ...           10 months ago
  • 0.4.1-beta.5                                ...           10 months ago
  • 0.4.1-beta.4                                ...           10 months ago
  • 0.4.1-beta.3                                ...           10 months ago
  • 0.4.1-beta.0                                ...           10 months ago
  • 0.4.0                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.1                                ...           2 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago

Copyright 2014 - 2017 © taobao.org |