1.0.1 • Published 5 years ago
deep-patch v1.0.1
Deep Patch
Modify an object recursively by an array of sequential patches.
Get Started
npm install deep-patchAPI
patch(input, patches)
Returns new Object modified recursively by mods, an array of one or more sequential patches.
input: Object input. (Object)patches: Array of patches. (Array)
patch operations
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.
Usage
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'
// }Benchmark
node benchmark.jsResults
$set x 135,799 ops/sec ±0.85% (85 runs sampled)License
See the License file.