object-rewrite
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "object-rewrite", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Rewrite an Object", | ||
@@ -10,3 +10,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"object-scan": "1.10.3" | ||
"object-scan": "1.10.4" | ||
}, | ||
@@ -13,0 +13,0 @@ "devDependencies": { |
@@ -28,12 +28,44 @@ [![Build Status](https://circleci.com/gh/blackflux/object-rewrite.png?style=shield)](https://circleci.com/gh/blackflux/object-rewrite) | ||
const data = [{/* ... */}, {/* ... */}]; | ||
const data = [{ | ||
guid: "aad8b948-a3de-4bff-a50f-3d59e9510aa9", | ||
count: 3, | ||
active: true, | ||
tags: [{ id: 1 }, { id: 2 }, { id: 3 }] | ||
}, { | ||
guid: "4409fb72-36e3-4385-b3da-b4944d028dcb", | ||
count: 4, | ||
active: true, | ||
tags: [{ id: 2 }, { id: 3 }, { id: 4 }] | ||
}, { | ||
guid: "96067a3c-caa2-4018-bcec-6969a874dad9", | ||
count: 5, | ||
active: false, | ||
tags: [{ id: 3 }, { id: 4 }, { id: 5 }] | ||
}]; | ||
const rewriter = objectRewrite({ | ||
exclude: {/* ... */}, | ||
inject: {/* ... */}, | ||
include: [/* ... */] | ||
exclude: { | ||
"": (key, value) => value.active !== true, | ||
tags: (key, value) => value.id !== 4 | ||
}, | ||
inject: { | ||
"": (key, value) => ({ count: value.count + 100 }) | ||
}, | ||
include: ["count", "active", "tags.id"] | ||
}); | ||
rewriter(data); | ||
// => data is now modified | ||
/* | ||
[{ | ||
"count": 103, | ||
"active": true, | ||
"tags": [] | ||
}, { | ||
"count": 104, | ||
"active": true, | ||
"tags": [{"id": 4}] | ||
}] | ||
*/ | ||
``` | ||
@@ -40,0 +72,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16634
93
+ Addedobject-scan@1.10.4(transitive)
- Removedobject-scan@1.10.3(transitive)
Updatedobject-scan@1.10.4