UNPKG

4.98 kBMarkdownView Raw
1# object-changes
2
3
4Compares 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
17import objectChanges from "object-changes"#
18const previousObject = {
19 unchanged: 2,
20 changed: 2,
21 removed: "a"
22}
23const nextObject = {
24 unchanged: 2,
25 changed: 3
26}
27const 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
36npm 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
40yarn 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
52Open a browser's JavaScript console and execute:
53
54```javascript
55const scriptElement = document.createElement("script");
56scriptElement.setAttribute("type", "text/javascript");
57scriptElement.setAttribute("src", "https://cdn.jsdelivr.net/npm/object-changes@1.0.0/index.js");
58document.querySelector("head").appendChild(scriptElement);
59```
60
61object-changes is now stored in the global variable `objectChanges`. The following console expression should return something other than `"undefined"`.
62
63```javascript
64typeof 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
82import objectChanges from "object-changes"
83const 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
99MIT License
100
101Copyright © 2019, Jaid <jaid.jsx@gmail.com> (github.com/jaid)
102
103Permission is hereby granted, free of charge, to any person obtaining a copy
104of this software and associated documentation files (the "Software"), to deal
105in the Software without restriction, including without limitation the rights
106to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
107copies of the Software, and to permit persons to whom the Software is
108furnished to do so, subject to the following conditions:
109
110The above copyright notice and this permission notice shall be included in all
111copies or substantial portions of the Software.
112
113THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
114IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
115FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
116AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
117LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
118OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
119SOFTWARE.
120```