ensure-key
v1.0.2
Published
Safe member access with initial value assignment.
Downloads
13
Maintainers
Readme
Ensure-Key
Lets you access members of an object safely (will be added if missing and initialized to a value you provide).
How to use:
import './Ensure';
const registry = {};
registry.ensure('abc', {}).ensure('items', []).push(123);
console.log(registry); // --> { abc: { items: [ 123 ] } }
The ensure method is added to the Object prototype and is thus available on every object. It is hidden from enumeration (to not cause interferences with environments).