Security News
Research
Supply Chain Attack on Rspack npm Packages Injects Cryptojacking Malware
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
@clipchamp/json-delta
Advanced tools
Json object diff / patching with configurable short-circuit tolerance. Forked from: github.com/corps
Forked from corps/json-delta
This for provides typings in the npm package. This fork will also be used to try and become more active for projects.
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));
npm i @clipchamp/json-delta
json-delta
json-delta
supplies two pretty main/important functions, at least for clipchamp.
diff<T>
diff<T>
takes two objects, and will return to you a Diff<T>
. This diff
object can only be applied to the type of object (supplied by T
). For example:
const coordinates1: Coordinates = {
x: 1,
y: 0
};
const coordinates2: Coordinates = {
x: 1,
y: 1
};
// This will result in the type of Diff<Coordinates>
const diffBetweenCoordinates = diff(coordinates1, coordinates2);
The resulting diff will be something like:
const someDiff = {
y: 0 => 1
}
applyDiff<T>
applyDiff<T>
will allow you to apply a diff you previous collected, back onto
the object (that follows the same generic typing of T
).
const coordinates1As2 = applyDiff(coordiantes1, diffBetweenCoordinates);
FAQs
Json object diff / patching with configurable short-circuit tolerance. Forked from: github.com/corps
The npm package @clipchamp/json-delta receives a total of 70 weekly downloads. As such, @clipchamp/json-delta popularity was classified as not popular.
We found that @clipchamp/json-delta demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 11 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.
Security News
Sonar’s acquisition of Tidelift highlights a growing industry shift toward sustainable open source funding, addressing maintainer burnout and critical software dependencies.