Modify an object recursively by an array of sequential patches.
npm install deep-patchReturns 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}}: Pushvalueto Array inpath.{path: {$unshift: value}}: Unshiftvalueto Array inpath.{path: {$filter: value}}: Runsvalueas filter Function to Array inpath.{path: {$map: value}}: Runsvalueas map Function to Array inpath.{path: {$apply: value}}: Runsvalueas Function to any value inpath. Input value in samepathis provided as first argument.{path: {$merge: value}}: MergesvalueintopathObject.
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.