Giter Site home page Giter Site logo

difflet's Introduction

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:

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

MIT/X11

difflet's People

Contributors

d3m3vilurr avatar papandreou avatar thlorenz avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.