I'm looking to reduce storage requirements for JSON data by deltifying it against a known set of defaults. Basically, what I want is an inverse for jQuery's .extend()
function, such that the following test passes for arbitrary JSON-compatible objects:
function test_delta(defaults, delta) {
var current = $.extend(true, {}, defaults, delta);
QUnit.same(get_delta(current, defaults), delta);
}
Before I start writing my own get_delta()
, is anyone aware of an existing implementation?
extend()
's innards, I was mostly just hoping not to have to write it myself. ;-) – Hypophosphatedelta
when the original one had some properties that were equal to the respective ones indefaults
. Noget_delta
would work for both the arbitrary JSON teststest_delta({a:1}, {a:1})
andtest_delta({a:1}, {})
. However if you only testedQUnit.same($.extend(true, {}, defaults, get_delta(current, defaults)), current)
there would be a trivial solution. – Luminosity