bubble-gum-create

0.0.10 • Public • Published

bubble-gum-create

Creates a new object or an initialized array depending on the input path

bubble-gum-create is part of bubble-gum-tools, check this here

Install

You can install bubble-gum-create using npm.

npm install --save bubble-gum-create

API Reference

bubble-gum-create

module.exports(path, initValue) ⇒ Object | Array

It creates a new object or an initialized array depending on the input path

Kind: Exported function
Returns: Object | Array - output - The new array or new object with the input path structure

Param Type Description
path Array Input path with the structure
initValue * Initial value for the end of the input path structure

Example

 const create = require('bubble-gum-create');
 
 // create nested arrays
 const nestedArray = create([0, 2, 0], 'bar');
 console.log(nestedArray); // => [ [ , , [ 'bar' ] ] ]
 
 // create nested objects
 const nestedObject = create(['root', 'foo', 'bar'], 'bar');
 console.log(nestedObject); // => { root: { foo: { bar: 'bar' } } }
 
 // no defined value
 const noDefaultVal = get(target, ['no', 'defined']);
 console.log(noDefaultVal); // => undefined
 
 // create both
 const mixed = create([0, 'nested', 'key'], 'value');
 console.log(mixed); // => [ { nested: { key: 'value' } } ]
 

License

MIT @ Nicolas Quiceno

Package Sidebar

Install

npm i bubble-gum-create

Weekly Downloads

0

Version

0.0.10

License

MIT

Last publish

Collaborators

  • nquicenob