Skip to content

Commit e5134fa

Browse files
jacwrightJacob Wright
authored andcommitted
Initial commit
0 parents  commit e5134fa

File tree

7 files changed

+547
-0
lines changed

7 files changed

+547
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Jacob Wright
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Differences.js
2+
3+
Differences.js takes two values of any kind and returns true or false if they are different. It also returns the
4+
differences if both values are objects or both values are arrays. Differences.js is used to test if inmutable values
5+
change over time. It assumes the first value is the current value and the second one is the old value when calculating
6+
differences.
7+
8+
## Usage
9+
10+
### Basic
11+
12+
To install Differences.js you can use npm.
13+
14+
```
15+
npm install differences-js
16+
```
17+
18+
To use Differences.js require it in your project.
19+
20+
```
21+
var diff = require('differences-js');
22+
var value1 = 'foo';
23+
var value2 = 'bar';
24+
25+
26+
if (diff.values(value1, value2)) {
27+
// the values are different
28+
} else {
29+
// the values are the same
30+
}
31+
```
32+
33+
The API only needs one method. `diff.values(currentValue, oldValue)`
34+
35+
You can find the changes between two objects.
36+
37+
```
38+
var changes = diff.values(obj1, obj2);
39+
40+
if (changes) {
41+
changes.forEach(function(change) {
42+
var currentValue = obj1[change.name];
43+
console.log(change.type, change.name, currentValue, change.oldValue);
44+
});
45+
}
46+
```
47+
48+
Each change in a list of object changes will have a `type` of `"new"`, `"updated"`, or `"deleted"`.
49+
50+
You can find the changes between two arrays.
51+
52+
```
53+
var splices = diff.values(array1, array2);
54+
55+
if (splices) {
56+
splices.forEach(function(splice) {
57+
console.log(splice.index, splice.removed, splice.addedCount);
58+
});
59+
}
60+
```
61+
62+
## Contributions and Issues
63+
64+
Please open a ticket for any bugs or feature requests.
65+
66+
Contributions are welcome. Please fork and send a pull-request.

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./src/diff');

package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "differences-js",
3+
"version": "0.1.0",
4+
"description": "Checks if there are any differences between two objects and provides the difference.",
5+
"keywords": [
6+
"templates",
7+
"data-binding",
8+
"javascript"
9+
],
10+
"homepage": "http://github.com/chip-js/differences-js",
11+
"author": {
12+
"name": "Jacob Wright",
13+
"email": "[email protected]",
14+
"url": "http://github.com/jacwright"
15+
},
16+
"repository": {
17+
"type": "git",
18+
"url": "https://github.com/chip-js/differences-js.git"
19+
},
20+
"bugs": {
21+
"url": "https://github.com/chip-js/differences-js/issues"
22+
},
23+
"licenses": {
24+
"type": "MIT",
25+
"url": "git://github.com/chip-js/differences-js/LICENSE"
26+
},
27+
"scripts": {
28+
"test": "mocha test"
29+
},
30+
"devDependencies": {
31+
"chai": "^3.4.1",
32+
"mocha": "^2.3.3"
33+
}
34+
}

0 commit comments

Comments
 (0)