Projekt

Obecné

Profil

Stáhnout (1.68 KB) Statistiky
| Větev: | Revize:
1 3a515b92 cagy
# value-equal [![Travis][build-badge]][build] [![npm package][npm-badge]][npm]
2
3
[build-badge]: https://img.shields.io/travis/mjackson/value-equal/master.svg?style=flat-square
4
[build]: https://travis-ci.org/mjackson/value-equal
5
[npm-badge]: https://img.shields.io/npm/v/value-equal.svg?style=flat-square
6
[npm]: https://www.npmjs.org/package/value-equal
7
8
[`value-equal`](https://www.npmjs.com/package/value-equal) determines if two JavaScript values are equal using [`Object.prototype.valueOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf).
9
10
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:
11
12
- Stuff you keep in `localStorage`
13
- `window.history.state` values
14
- Query strings
15
16
## Installation
17
18
Using [npm](https://www.npmjs.com/):
19
20
    $ npm install --save value-equal
21
22
Then with a module bundler like [webpack](https://webpack.github.io/), use as you would anything else:
23
24
```js
25
// using ES6 modules
26
import valueEqual from 'value-equal';
27
28
// using CommonJS modules
29
var valueEqual = require('value-equal');
30
```
31
32
The UMD build is also available on [unpkg](https://unpkg.com):
33
34
```html
35
<script src="https://unpkg.com/value-equal"></script>
36
```
37
38
You can find the library on `window.valueEqual`.
39
40
## Usage
41
42
```js
43
valueEqual(1, 1); // true
44
valueEqual('asdf', 'asdf'); // true
45
valueEqual('asdf', new String('asdf')); // true
46
valueEqual(true, true); // true
47
valueEqual(true, false); // false
48
valueEqual({ a: 'a' }, { a: 'a' }); // true
49
valueEqual({ a: 'a' }, { a: 'b' }); // false
50
valueEqual([1, 2, 3], [1, 2, 3]); // true
51
valueEqual([1, 2, 3], [2, 3, 4]); // false
52
```
53
54
That's it. Enjoy!