UNPKG

2.17 kBMarkdownView Raw
1# shallowequal [![Build Status](https://travis-ci.org/dashed/shallowequal.svg)](https://travis-ci.org/dashed/shallowequal) [![Downloads](https://img.shields.io/npm/dm/shallowequal.svg)](https://npmjs.com/shallowequal) [![npm version](https://img.shields.io/npm/v/shallowequal.svg?style=flat)](https://www.npmjs.com/package/shallowequal)
2
3> `shallowequal` is like lodash's [`isEqual`](https://lodash.com/docs/3.10.1#isEqual) (v3.10.1) but for shallow (strict) equal.
4
5`shallowequal(value, other, [customizer], [thisArg])`
6
7Performs a **_shallow equality_** comparison between two values (i.e. `value` and `other`) to determine if they are equivalent.
8
9The equality check returns true if `value` and `other` are already strictly equal, OR when all the following are true:
10
11- `value` and `other` are both objects with the same keys
12- For each key, the value in `value` and `other` are **strictly equal** (`===`)
13
14If `customizer` (expected to be a function) is provided it is invoked to compare values. If `customizer` returns `undefined` (i.e. `void 0`), then comparisons are handled by the `shallowequal` function instead.
15
16The `customizer` is bound to `thisArg` and invoked with three arguments: `(value, other, key)`.
17
18**NOTE:** Docs are (shamelessly) adapted from [lodash's v3.x docs](https://lodash.com/docs/3.10.1#isEqual)
19
20## Install
21
22```sh
23$ yarn add shallowequal
24# npm v5+
25$ npm install shallowequal
26# before npm v5
27$ npm install --save shallowequal
28```
29
30## Usage
31
32```js
33const shallowequal = require("shallowequal");
34
35const object = { user: "fred" };
36const other = { user: "fred" };
37
38object == other;
39// → false
40
41shallowequal(object, other);
42// → true
43```
44
45## Credit
46
47Code for `shallowEqual` originated from https://github.com/gaearon/react-pure-render/ and has since been refactored to have the exact same API as `lodash.isEqualWith` (as of `v4.17.4`).
48
49## Development
50
51- `node.js` and `npm`. See: https://github.com/creationix/nvm#installation
52- `yarn`. See: https://yarnpkg.com/en/docs/install
53- `npm` dependencies. Run: `yarn install`
54
55### Chores
56
57- Lint: `yarn lint`
58- Test: `yarn test`
59- Pretty: `yarn pretty`
60- Prepare: `yarn prepare`
61
62## License
63
64MIT.