Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/herrmanno/deep-obj-utils
Utilities to handle immutable objects without pain
https://github.com/herrmanno/deep-obj-utils
immutable javascript typescript
Last synced: 4 days ago
JSON representation
Utilities to handle immutable objects without pain
- Host: GitHub
- URL: https://github.com/herrmanno/deep-obj-utils
- Owner: herrmanno
- License: isc
- Created: 2018-03-23T17:55:13.000Z (over 6 years ago)
- Default Branch: develop
- Last Pushed: 2019-05-15T09:21:34.000Z (over 5 years ago)
- Last Synced: 2024-02-22T21:10:04.860Z (9 months ago)
- Topics: immutable, javascript, typescript
- Language: TypeScript
- Homepage: https://herrmanno.github.io/deep-obj-utils/api
- Size: 207 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# deep-obj-utils
deep-obj-utils is an utility library for modifieng (e. g. cloning) immutable objects while changing nested properties.
## Installation
```shell
npm i deep-obj-utils
```## Examples
```javascript
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/](https://herrmanno.github.io/deep-obj-utils/api/).
This project is licensed under the [ISC license](LICENSE).