dynamic-props

1.0.1 • Public • Published

dynamic-props

dynamic-props allows to create and delete nested properties of object literals dynamically.

Usage

import { setNestedProp } from 'dynamic-props';

const foo = {};

setNestedProp`bar.baz[${2}].qux`(foo, 'hello');

console.log(foo);

{ bar: { baz: [ <2 empty items>, { qux: 'hello' } ] } }

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.

$ npm install dynamic-props --save

/dynamic-props/

    Package Sidebar

    Install

    npm i dynamic-props

    Weekly Downloads

    10

    Version

    1.0.1

    License

    Apache-2.0

    Unpacked Size

    18.8 kB

    Total Files

    6

    Last publish

    Collaborators

    • mathieuprog