ensure-key

1.0.2 • Public • Published

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).

Package Sidebar

Install

npm i ensure-key

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

1.98 kB

Total Files

4

Last publish

Collaborators

  • matthias.truxa