react-json-fp

1.0.1 • Public • Published

deep-ply

A simple javascript library for applying a function deeply.

Installation

npm install deep-ply

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" },
//   ],
// }

Package Sidebar

Install

npm i react-json-fp

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

7.9 kB

Total Files

6

Last publish

Collaborators

  • rlee0