deep-ply
v1.1.0
Published
A simple javascript library for applying a function deeply.
Downloads
7
Readme
deep-ply
A simple javascript library for applying a function deeply.
Installation
npm install deep-ply
Demo
Usage
import { deepPly } from "deep-ply"
const data = {
id: "1",
value: "foo",
items: [
{ id: "1.1", value: "bar", items: [{ id: "1.1.1", value: "qux" }] },
{ id: "1.2", value: "quux" },
],
}
const callback = (value, path) => {
if (path === "/items/0/value") return value.toUpperCase()
return value
}
deepPly(callback)(data)
// {
// "id": "1",
// "value": "foo",
// "items": [
// { "id": "1.1", "value": "BAR", "items": [{ "id": "1.1.1", "value": "qux" }] },
// { "id": "1.2", "value": "quux" }
// ]
// }