Giter VIP home page Giter VIP logo

json-delta's Introduction

json-delta

json-delta is an efficient, JSON oriented javascript object delta calculator and applier. It provides a configurable threshold (tolerance) after which the diff calculator will short circuit a more complex delta analysis, useful for calculating deltas on very large objects that may from time to time be fully replaced.

Unlike similar libraries, json-delta sacrifices certain features and makes certain sane assumptions that allow it to perform.

For instance, it treats undefined as null and does not preserve constructor or prototype-bound behaviors. Arrays are not diffed recursively -- any elements with property changes result in single replacement delta of that element. Objects are diffed recursively, however, so only the deepest nodes of a structure have their changes tracked.

diff(a, b, tolerance?) returns a simple array describing the changes needed to transform a to b. It will return null if a and b are deeply equal, and will return a single replacement delta if more than tolerance (number) of changes are found.

applyDiff(a, diff) returns an object that would be deeply equal to b.

applyDiff will not mutate the original a, although it may share references to container objects not changed in the patching. It uses shallow copying on any container that changes.

var jd = require("json-delta");
var diff = jd.diff([1, 2, 3], [1, 2, 3, 4]);
console.log(jd.applyDiff([1, 2, 3], diff));

Installation

npm install json-delta --save

json-delta's People

Contributors

corps avatar wms 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.