Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mathieuprog/dynamic-props
Create and delete nested properties of object literals dynamically
https://github.com/mathieuprog/dynamic-props
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
- Owner: mathieuprog
- License: apache-2.0
- Created: 2021-04-13T12:43:10.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-30T15:02:08.000Z (almost 3 years ago)
- Last Synced: 2024-10-04T08:06:25.003Z (3 months ago)
- Language: JavaScript
- Size: 79.1 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`
`dynamic-props` allows to create and delete nested properties of object literals dynamically.
## Usage
```javascript
import { setNestedProp } from 'dynamic-props';const foo = {};
setNestedProp`bar.baz[${2}].qux`(foo, 'hello');
console.log(foo);
```> { bar: { baz: [ <2 empty items>, { qux: 'hello' } ] } }
```javascript
import { deleteNestedProp } from 'dynamic-props';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` via [npm](http://npmjs.com).
```bash
$ npm install dynamic-props --save
```