1 | # object-changes
|
2 |
|
3 |
|
4 | Compares two objects and returns the differences.
|
5 |
|
6 | <a href="https://raw.githubusercontent.com/Jaid/object-changes/master/license.txt"><img src="https://img.shields.io/github/license/Jaid/object-changes?style=flat-square&color=success" alt="License"/></a>
|
7 | <a href="https://github.com/Jaid/object-changes/commits"><img src="https://img.shields.io/github/commits-since/Jaid/object-changes/v1.0.0?style=flat-square&logo=github&color=success" alt="Commits since v1.0.0"/></a> <a href="https://github.com/Jaid/object-changes/commits"><img src="https://img.shields.io/github/last-commit/Jaid/object-changes?style=flat-square&logo=github&color=red" alt="Last commit"/></a> <a href="https://github.com/Jaid/object-changes/issues"><img src="https://img.shields.io/github/issues/Jaid/object-changes?style=flat-square&logo=github&color=red" alt="Issues"/></a>
|
8 | <a href="https://npmjs.com/package/object-changes"><img src="https://img.shields.io/npm/v/object-changes?style=flat-square&logo=npm&label=latest%20version&color=success" alt="Latest version on npm"/></a> <a href="https://github.com/Jaid/object-changes/network/dependents"><img src="https://img.shields.io/librariesio/dependents/npm/object-changes?style=flat-square&logo=npm&color=red" alt="Dependents"/></a> <a href="https://npmjs.com/package/object-changes"><img src="https://img.shields.io/npm/dm/object-changes?style=flat-square&logo=npm&color=red" alt="Downloads"/></a>
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | ## Usage
|
15 |
|
16 | ```js
|
17 | import objectChanges from "object-changes"#
|
18 | const previousObject = {
|
19 | unchanged: 2,
|
20 | changed: 2,
|
21 | removed: "a"
|
22 | }
|
23 | const nextObject = {
|
24 | unchanged: 2,
|
25 | changed: 3
|
26 | }
|
27 | const result = objectChanges(previousObject, nextObject)
|
28 | // Result: {changed: 3, removed: undefined}
|
29 | ```
|
30 |
|
31 |
|
32 |
|
33 | ## Installation
|
34 | <a href="https://npmjs.com/package/object-changes"><img src="https://img.shields.io/badge/npm-object--changes-C23039?style=flat-square&logo=npm" alt="object-changes on npm"/></a>
|
35 | ```bash
|
36 | npm install --save object-changes@^1.0.0
|
37 | ```
|
38 | <a href="https://yarnpkg.com/package/object-changes"><img src="https://img.shields.io/badge/Yarn-object--changes-2F8CB7?style=flat-square&logo=yarn&logoColor=white" alt="object-changes on Yarn"/></a>
|
39 | ```bash
|
40 | yarn add object-changes@^1.0.0
|
41 | ```
|
42 | <a href="https://jsdelivr.com/package/npm/object-changes/"><img src="https://img.shields.io/badge/jsDelivr-object--changes-orange?style=flat-square&logo=html5&logoColor=white" alt="object-changes on jsDelivr"/></a> <a href="https://unpkg.com/browse/object-changes/"><img src="https://img.shields.io/badge/UNPKG-object--changes-orange?style=flat-square&logo=html5&logoColor=white" alt="object-changes on UNPKG"/></a>
|
43 | ```html
|
44 | <script src="https://cdn.jsdelivr.net/npm/object-changes@1.0.0/index.js"/>
|
45 | ```
|
46 |
|
47 |
|
48 | ## Try it out
|
49 |
|
50 |
|
51 |
|
52 | Open a browser's JavaScript console and execute:
|
53 |
|
54 | ```javascript
|
55 | const scriptElement = document.createElement("script");
|
56 | scriptElement.setAttribute("type", "text/javascript");
|
57 | scriptElement.setAttribute("src", "https://cdn.jsdelivr.net/npm/object-changes@1.0.0/index.js");
|
58 | document.querySelector("head").appendChild(scriptElement);
|
59 | ```
|
60 |
|
61 | object-changes is now stored in the global variable `objectChanges`. The following console expression should return something other than `"undefined"`.
|
62 |
|
63 | ```javascript
|
64 | typeof objectChanges.default
|
65 | ```
|
66 |
|
67 | <a name="module_object-changes"></a>
|
68 |
|
69 | ## Reference
|
70 | <a name="exp_module_object-changes--module.exports"></a>
|
71 |
|
72 | ### module.exports([compareValue]) ⇒ <code>Object</code> ⏏
|
73 | **Kind**: Exported function
|
74 | **Returns**: <code>Object</code> - Seconds passed since Unix epoch (01 January 1970)
|
75 |
|
76 | | Param | Type |
|
77 | | --- | --- |
|
78 | | [compareValue] | <code>number</code> |
|
79 |
|
80 | **Example**
|
81 | ```javascript
|
82 | import objectChanges from "object-changes"
|
83 | const result = objectChanges({
|
84 | unchanged: 2,
|
85 | changed: 2
|
86 | },
|
87 | { unchanged: 2,
|
88 | changed: 3
|
89 | })
|
90 | // Result: {changed: 3}
|
91 | ```
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | ## License
|
98 | ```text
|
99 | MIT License
|
100 |
|
101 | Copyright © 2019, Jaid <jaid.jsx@gmail.com> (github.com/jaid)
|
102 |
|
103 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
104 | of this software and associated documentation files (the "Software"), to deal
|
105 | in the Software without restriction, including without limitation the rights
|
106 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
107 | copies of the Software, and to permit persons to whom the Software is
|
108 | furnished to do so, subject to the following conditions:
|
109 |
|
110 | The above copyright notice and this permission notice shall be included in all
|
111 | copies or substantial portions of the Software.
|
112 |
|
113 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
114 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
115 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
116 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
117 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
118 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
119 | SOFTWARE.
|
120 | ```
|