https://github.com/jcoreio/mutate
a few immutable.js-like mutation functions for plain objects
https://github.com/jcoreio/mutate
deep immutable json mutations set-in update update-in
Last synced: about 1 month ago
JSON representation
a few immutable.js-like mutation functions for plain objects
- Host: GitHub
- URL: https://github.com/jcoreio/mutate
- Owner: jcoreio
- License: mit
- Created: 2018-01-05T20:40:29.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-07-25T19:06:26.000Z (almost 3 years ago)
- Last Synced: 2025-09-15T05:27:08.804Z (9 months ago)
- Topics: deep, immutable, json, mutations, set-in, update, update-in
- Language: TypeScript
- Size: 1.49 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# @jcoreio/mutate
[](https://travis-ci.org/jcoreio/mutate)
[](https://codecov.io/gh/jcoreio/mutate)
[](https://github.com/semantic-release/semantic-release)
[](http://commitizen.github.io/cz-cli/)
a few immutable.js-like mutation functions for plain objects
Beware of using Ramda.js! [It always returns a new object, even if nothing changed!](https://github.com/ramda/ramda/issues/2429)
# Usage
```sh
pnpm install --save @jcoreio/mutate
```
# API
## `setIn(obj: any, path: Iterable, newValue: any): any`
```js
const { setIn } = require('@jcoreio/mutate')
```
Works just like [`setIn` from Immutable.js](https://facebook.github.io/immutable-js/docs/#/setIn)
but operates on nested JS Objects and Arrays.
## `updateIn(obj: any, path: Iterable, [notSetValue: any], updater: (value: any) => any): any`
```js
const { updateIn } = require('@jcoreio/mutate')
```
Works just like [`updateIn` from Immutable.js](https://facebook.github.io/immutable-js/docs/#/setIn)
but operates on nested JS Objects and Arrays.