Skip to content

Commit

Permalink
Merge pull request #9 from omgaz/upgrade
Browse files Browse the repository at this point in the history
[major] upgrade deps and readme
  • Loading branch information
omgaz committed Jul 20, 2019
2 parents 69ca90f + 3bf27b4 commit 09de6b8
Show file tree
Hide file tree
Showing 12 changed files with 810 additions and 1,468 deletions.
24 changes: 2 additions & 22 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Editors
.vscode

# Dependency directory
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules

# Users Environment Variables
.lock-wscript
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
language: node_js
node_js:
- "8"
addons:
chrome: stable
- "12"
71 changes: 41 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,58 @@
js-diff
=======
<div align="center">
<img src="stuff/AppIcon-readme.png" height="200" />
<h1>diffler</h1>
<p>
<b>A recursive JSON comparison script for humans</b>
</p>
<br>
<br>
</div>

[![Build Status](https://travis-ci.org/omgaz/js-diff.svg?branch=master)](https://travis-ci.org/omgaz/js-diff)
## Motivation

To compare JSON objects containing asset metadata for a digital library. Upon change of any metadata, we'd store these changes as an audit trail and email asset stakeholders for review and approval of the changes.

## Dependencies

diffler is written with Node v12 in mind.
Tests depend on [Mocha](https://mochajs.org/).

## Usage

```bash
npm install diffler
```

A basic JavaScript object comparison script that will iterate, recursivly, through two JSON objects to compare differences.
### Params

This was built for a project in which I had a JSON object of user data that I cached on page load and compared against an edited version on save. I used this information to construct email summaries of changed behaviour as well as provide a detailed audit trail of actions.
`obj1` and `obj2` are two JSON objects for comparison.

Code
----
Code can be found under `src` at [src/diff.js](src/diff.js). That's all you need to worry about and the code has no dependencies on any library. NodeJS and all the other files are purely for running tests.
### Return

Params
------
`obj1` and `obj2` are two objects to be compared.
If no difference: returns `{}` *(empty object)*

Return
------
Returns `false` if no differences are found.
Returns an `object` if differences are found. The object will maintain path structure where the value fot he changed key/value pair is highlighted by from and to fields.
If difference: A JSON object with preserved path structure. The resulting values will be an object with `from` and `to` fields.

Example
-------
### Example

var x = { name: "omgaz", location: "London" };
var y = { name: "omgaz", location: "Melbourne" };
```js
const jsDiff = require('diffler');

getDiff(x, y);
const before = { name: "omgaz", location: "London" };
const after = { name: "omgaz", location: "Melbourne" };

// Returns object
{
location: {
from: "London",
to: "Melbourne"
}
}
const difference = jsDiff(before, after);
console.log(difference); // { location: { from: "London", to: "Melbourne" } }
```

Tests
-----

[![Build Status](https://travis-ci.org/omgaz/js-diff.svg?branch=master)](https://travis-ci.org/omgaz/js-diff)

If you'd like to run tests, check out the whole project. You'll need NodeJS installed. Tests use Karma and ChromeHeadless.
If you'd like to run tests, check out the whole project. You'll need NodeJS installed. Tests use Mocha.

npm install
npm test
```bash
npm install
npm test
```
68 changes: 0 additions & 68 deletions karma.conf.js

This file was deleted.

32 changes: 0 additions & 32 deletions lib/test-factory.js

This file was deleted.

Loading

0 comments on commit 09de6b8

Please sign in to comment.