safe-access-check
⚠️ Experimental. Intended to be used by compilers and code checkers ⚠️
Todos
- Existential check of enumerable properties
- Optional logging of values recieved
- Clearer, more consistent error messages
Installation
npm install --save-dev safe-access-check
Usage
; // ------------------------------------------------// 1. Usage as an expression// ------------------------------------------------let some = moo + '10' // 'moo10'some = // 'moo10' // ------------------------------------------------// 2. Usage for coercion safeguard// ------------------------------------------------ + {} // "[object Object]" // TypeError: 'Unexpected coercion of type "Object" and// type "Array" using "+" operator' NaN + undefined // NaN ;// TypeError: Unexpected coercion of type "NaN" and type// "undefined" using "+" operator ;// TypeError: Unexpected comparison of type "String" and type// "number" using ">" operator // ------------------------------------------------// 3. Usage for better undefined propagation errors// ------------------------------------------------const obj = foo: bar: baz: false objfoobar_MOO_baz;// TypeError: 'Cannot read property 'baz' of undefined' ;// TypeError: Property "_MOO_" does not exist in "Object.foo._MOO_" // ------------------------------------------------// 4. Usage as out of bounds check// ------------------------------------------------const obj = woo: '' objwoo1 // undefined // TypeError: '"woo[1]" is out of bounds'