Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tdegrunt/difflet
colorful diffs for javascript objects
https://github.com/tdegrunt/difflet
Last synced: 26 days ago
JSON representation
colorful diffs for javascript objects
- Host: GitHub
- URL: https://github.com/tdegrunt/difflet
- Owner: tdegrunt
- Created: 2012-06-25T20:28:50.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-02-21T07:03:18.000Z (over 12 years ago)
- Last Synced: 2024-10-07T17:36:24.812Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 83 KB
- Stars: 1
- Watchers: 3
- Forks: 23
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
difflet
=======Create colorful diffs for javascript objects.
example
=======string.js
---------``` js
var difflet = require('difflet');var s = difflet.compare({ a : 2, c : 5 }, { a : 3, b : 4 });
process.stdout.write(s);
```output:
![colorful output](http://substack.net/images/screenshots/difflet_string.png)
colors.js
---------``` js
var diff = require('difflet')({ indent : 2 });var prev = {
yy : 6,
zz : 5,
a : [1,2,3],
fn : 'beep',
c : { x : 7, z : 3 }
};var next = {
a : [ 1, 2, "z", /beep/, new Buffer(3) ],
fn : function qqq () {},
b : [5,6,7],
c : { x : 8, y : 5 }
};diff(prev, next).pipe(process.stdout);
```output:
![colorful output](http://substack.net/images/screenshots/difflet_colors.png)
green for inserts, blue for updates, red for deletes
methods
=======var difflet = require('difflet')
var diff = difflet(opts={})
---------------------------Create a difflet from optional options `opts`.
With `opts.start(type, stream)` and `opts.stop(type, stream)`,
you can write custom handlers for all the types of differences:
`'inserted'`, `'updated'`, and `'deleted'`.
By default green is used for insertions, blue for updates, and red for
deletions.If `opts.indent` is set, output will span multiple lines and `opts.indent`
spaces will be used for leading whitespace.If `opts.comma === 'first'` then commas will be placed at the start of lines.
Setting `opts.comment` to `true` will turn on comments with the previous
contents like this:![object comments](http://substack.net/images/screenshots/difflet_object_comments.png)
diff(prev, next)
----------------Return a stream with the colorful changes between objects `prev` and `next`.
diff.compare(prev, next)
------------------------Return a string with the colorful changes between `prev` and `next`.
difflet.compare(prev, next)
---------------------------Return a string with the colorful changes between `prev` and `next` with the
default options.install
=======With [npm](http://npmjs.org) do:
```
npm install difflet
```test
====With [npm](http://npmjs.org) do:
```
npm test
```license
=======MIT/X11