Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/int64ago/mutate
Modify object and return immutable object.
https://github.com/int64ago/mutate
functional-programming immutable
Last synced: about 1 month ago
JSON representation
Modify object and return immutable object.
- Host: GitHub
- URL: https://github.com/int64ago/mutate
- Owner: int64ago
- License: mit
- Created: 2018-01-11T10:49:15.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T02:44:20.000Z (almost 2 years ago)
- Last Synced: 2024-10-07T08:35:57.464Z (about 1 month ago)
- Topics: functional-programming, immutable
- Language: JavaScript
- Size: 734 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mutate
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Downloads][downloads-image]][npm-url]
Modify object and return immutable object.
## Usage
```bash
npm i @hspkg/mutate -S
```### API
```js
/**
* Modify object and return immutable object
* @param {object} params The source object
* @param {any} value The value to be set
* @param {string[]} keys The keys in chain
* @returns {object}
*/
mutate(params, value, ...keys);
```### Examples
```js
import mutate from '@hspkg/mutate';const source = {
key1: 123,
key3: 'test3',
key4: {
key5: {
key6: 'Hello',
key7: 'World'
}
}
};console.log(mutate(source, 'hack', 'key4', 'key5', 'key6'));
// {
// "key1": 123,
// "key3": "test3",
// "key4": {
// "key5": {
// "key6": "hack",
// "key7": "World"
// }
// }
// }console.log(mutate(source, 'hack', 'key4', 'key5', 'key8'));
// {
// "key1": 123,
// "key3": "test3",
// "key4": {
// "key5": {
// "key6": "Hello",
// "key7": "World",
// "key8": "hack"
// }
// }
// }
```## Test
```bash
npm test
```## License
[![License][license-image]][license-url]
[downloads-image]: https://img.shields.io/npm/dt/@hspkg/mutate.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@hspkg/mutate
[npm-image]: https://img.shields.io/npm/v/@hspkg/mutate.svg?style=flat-square[travis-url]: https://travis-ci.com/int64ago/mutate
[travis-image]: https://img.shields.io/travis/com/int64ago/mutate.svg?style=flat-square[license-url]: https://github.com/int64ago/mutate/blob/master/LICENSE
[license-image]: https://img.shields.io/github/license/int64ago/mutate.svg?style=flat-square