Modify an object recursively by an array of sequential patches.
npm install deep-patch
Returns new Object modified recursively by mods
, an array of one or more sequential patches.
input
: Object input. (Object)patches
: Array of patches. (Array)
If path
is not found in input
, a new value is created. Type is defined by expected value.
{path: {$set: value}}
: Set a mixed value topath
.{path: {$push: value}}
: Pushvalue
to Array inpath
.{path: {$unshift: value}}
: Unshiftvalue
to Array inpath
.{path: {$filter: value}}
: Runsvalue
as filter Function to Array inpath
.{path: {$map: value}}
: Runsvalue
as map Function to Array inpath
.{path: {$apply: value}}
: Runsvalue
as Function to any value inpath
. Input value in samepath
is provided as first argument.{path: {$merge: value}}
: Mergesvalue
intopath
Object.
var patch = require("deep-patch");
var data = {
a: { aa: { aaa: "string" } },
b: "string",
};
patch(data, [
{ a: { aa: { aaa: { $set: "modified string" } } } },
{ b: { $set: "modified string" } },
]);
// →
// {
// a: {aa: {aaa: 'modified string' }},
// b: 'modified string'
// }
node benchmark.js
$set x 135,799 ops/sec ±0.85% (85 runs sampled)
See the License file.