difflet
    Overview
    Documentation
    Insights
    Code
    Contributors
    Dependencies
    Alternatives

difflet

colorful diffs for javascript objects

1.0.1  •  Updated 2 years ago  •  by James Halliday  •  MIT License

difflet

Create colorful diffs for javascript objects.

example

string.js

var difflet = require('difflet');

var s = difflet.compare({ a : 2, c : 5 }, { a : 3, b : 4 });
process.stdout.write(s);

output:

colorful output

colors.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

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:

Setting opts.deepEqual allows a different equality function to be used. By default deep-is is used.

object comments

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 do:

npm install difflet

test

With npm do:

npm test

license

Copyright © 2012, 2013 James Halliday mail@substack.net

Licensed under the MIT license, see LICENSE for details.

How often do you use dark themes on other websites?

Popularity

Weekly Downloads
9.5K
Stars
212

Maintenance

Development

Last ver 4 years ago
Created 8 years ago
Last commit 4 years ago
1 month between commits

Technology

Node version: 4.2.1
0 unpacked

Compliance

MIT License
OSI Approved
0 vulnerabilities

Contributors

7 contributors
James Halliday
Maintainer, 55 commits, 6 merges
Works at bits.coop
Andreas Lind Petersen
3 commits, 1 PRs
Works at peakon
Thorsten Lorenz
2 commits, 3 PRs
Sunguk Lee
2 commits, 1 PRs
Works at EA
Ben Kitzelman
2 commits, 1 PRs
Works at Ambisie
David Humphrey (:humph) david.humphrey@senecacollege.ca
1 commits, 1 PRs

Tags

diff
object
compare
Ready for the next level?
Join Openbase's founding team to help us build the ultimate open-source app store, work with the latest technologies, and enjoy great culture, impact and autonomy
Openbase helps developers choose among and use millions of open-source packages, so they can build amazing products faster.
© 2020 Devstore, Inc.