1 | # is-equal-shallow [![NPM version](https://badge.fury.io/js/is-equal-shallow.svg)](http://badge.fury.io/js/is-equal-shallow) [![Build Status](https://travis-ci.org/jonschlinkert/is-equal-shallow.svg)](https://travis-ci.org/jonschlinkert/is-equal-shallow)
|
2 |
|
3 | > Does a shallow comparison of two objects, returning false if the keys or values differ.
|
4 |
|
5 | The purpose of this lib is to do the fastest comparison possible of two objects when the values will predictably be primitives.
|
6 |
|
7 | * only compares objects.
|
8 | * only compares the first level of each object
|
9 | * values must be primitives. If a value is not a primitive, even if the values are the same, `false` is returned.
|
10 |
|
11 | Install with [npm](https://www.npmjs.com/)
|
12 |
|
13 | ```sh
|
14 | $ npm i is-equal-shallow --save
|
15 | ```
|
16 |
|
17 | ## Usage
|
18 |
|
19 | ```js
|
20 | var equals = require('is-equal-shallow');
|
21 | equals(object_a, object_b);
|
22 | ```
|
23 |
|
24 | **Examples**
|
25 |
|
26 | ```js
|
27 | equals({a: true, b: true}, {a: true, b: true});
|
28 | //=> 'true'
|
29 |
|
30 | equals({a: true, b: false}, {c: false, b: false});
|
31 | //=> 'false'
|
32 |
|
33 | equals({a: true, b: false}, {a: false, b: false});
|
34 | //=> 'false'
|
35 | ```
|
36 |
|
37 | Strict comparison for equality:
|
38 |
|
39 | ```js
|
40 | equals({a: true, b: true}, {a: true, b: 'true'});
|
41 | //=> 'false'
|
42 | ```
|
43 |
|
44 | When values are not primitives, `false` is always returned:
|
45 |
|
46 | ```js
|
47 | equals({ b: {}}, { b: {}});
|
48 | //=> 'false'
|
49 |
|
50 | equals({ b: []}, { b: []});
|
51 | //=> 'false'
|
52 | ```
|
53 |
|
54 | ## Related projects
|
55 |
|
56 | Other object utils:
|
57 |
|
58 | * [clone-deep](https://github.com/jonschlinkert/clone-deep): Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives.
|
59 | * [for-in](https://github.com/jonschlinkert/for-in): Iterate over the own and inherited enumerable properties of an objecte, and return an object… [more](https://github.com/jonschlinkert/for-in)
|
60 | * [for-own](https://github.com/jonschlinkert/for-own): Iterate over the own enumerable properties of an object, and return an object with properties… [more](https://github.com/jonschlinkert/for-own)
|
61 | * [is-plain-object](https://github.com/jonschlinkert/is-plain-object): Returns true if an object was created by the `Object` constructor.
|
62 | * [isobject](https://github.com/jonschlinkert/isobject): Returns true if the value is an object and not an array or null.
|
63 |
|
64 | ## Running tests
|
65 |
|
66 | Install dev dependencies:
|
67 |
|
68 | ```sh
|
69 | $ npm i -d && npm test
|
70 | ```
|
71 |
|
72 | ## Contributing
|
73 |
|
74 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/is-equal-shallow/issues/new)
|
75 |
|
76 | ## Author
|
77 |
|
78 | **Jon Schlinkert**
|
79 |
|
80 | + [github/jonschlinkert](https://github.com/jonschlinkert)
|
81 | + [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
|
82 |
|
83 | ## License
|
84 |
|
85 | Copyright © 2015 Jon Schlinkert
|
86 | Released under the MIT license.
|
87 |
|
88 | ***
|
89 |
|
90 | _This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on June 22, 2015._ |
\ | No newline at end of file |