shared
utils
string
object
is
extension
js
tracking
string
dom
when
selection
position
iframe
event
scroll
console
node
string
project
fs
console
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
- obj*-Object
The object on which to check the path existence
- path*-String
The dotted object path to check
- 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
Author
- Olivier Bosselolivier.bossel@gmail.comhttps://blackbyte.space