ensurePropertyExists

Type:Function
Status:stable
Since:1.0.0
Platform:jsnode
@blackbyte.sugar.shared.object

Pass a string like “my.cool.object” and the value it has to be and this function will ensure that this deep object exist

Params

  1. obj*-Object

    The object on which to check the path existence

  2. path*-String

    The dotted object path to check

  3. value*-Mixed

    The value to set to the object path created if not already exist

Example

import { ensurePropertyExists } from '@blackbyte/sugar/object';
const myObj = { hello: 'world'
ensurePropertyExists(myObj, 'cool.object', {});
// { hello: 'world', cool: { object: {} } }

Todo

  • testsnormal