Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mathieuprog/dynamic-props-immutable
Create and delete nested properties of object literals dynamically
https://github.com/mathieuprog/dynamic-props-immutable
Last synced: about 2 months ago
JSON representation
Create and delete nested properties of object literals dynamically
- Host: GitHub
- URL: https://github.com/mathieuprog/dynamic-props-immutable
- Owner: mathieuprog
- License: apache-2.0
- Created: 2021-10-15T08:54:29.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-02T08:15:53.000Z (almost 3 years ago)
- Last Synced: 2024-08-10T07:01:46.922Z (5 months ago)
- Language: JavaScript
- Size: 136 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `dynamic-props-immutable`
`dynamic-props-immutable` allows to create and delete nested properties of object literals dynamically.
## Usage
```javascript
import { setNestedProp } from 'dynamic-props-immutable';let foo = {};
foo = setNestedProp`bar.baz[${2}].qux`(foo, 'hello');
console.log(foo);
```> { bar: { baz: [ <2 empty items>, { qux: 'hello' } ] } }
```javascript
import { deleteNestedProp } from 'dynamic-props-immutable';foo = deleteNestedProp`bar.baz[${2}].qux`(foo);
console.log(foo);
```> { }
Note that by default `deleteNestedProp` recursively removes properties containing undefined values, empty objects, empty arrays or arrays containing only undefined values.
## Limitations
Multidimensional arrays are not supported.
## Installation
You can get `dynamic-props-immutable` via [npm](http://npmjs.com).
```bash
$ npm install dynamic-props-immutable --save
```