deep-obj-utils
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-rc.6 • Public • Published

deep-obj-utils

deep-obj-utils is an utility library for modifieng (e. g. cloning) immutable objects while changing nested properties.

Installation

npm i deep-obj-utils

Examples

import { get, set, update } from "deep-obj-utils"

// retrieving nested values

const object = { foo: { bar: "baz" } }
get(["foo", "bar"], object) // "baz"

const object = [[null, "baz"]]
get([0, 1], object) // "baz"


// creating objects with changed nested properties

const object = { foo: { bar: "bar" } }
set(["foo", "bar"], object, "baz") // { foo: { bar: "baz" } }

const object = { foo: { bar: "bar" } }
update(["foo", "bar"], object, v => v.toUpperCase()) // { foo: { bar: "BAR" } }


// auto vivication

const object = {}
set(["foo", 0, "baz"], object, "baz") // { foo: ["baz", { bar: "BAR" }] }

Api

The documentation can be found at herrmanno.github.io/deep-obj-utils/api/.

This project is licensed under the ISC license.

Package Sidebar

Install

npm i deep-obj-utils

Weekly Downloads

7

Version

1.0.0-rc.6

License

ISC

Unpacked Size

31 kB

Total Files

31

Last publish

Collaborators

  • herrmanno