npm.io
2.1.0 • Published 5 years ago

noerr

Licence
MIT
Version
2.1.0
Deps
0
Size
3 kB
Vulns
0
Weekly
0
Stars
3

noerr

Safe property reference chaining without errors.
Only TypeError can be suppressed.

const a = { b: 1 };

console.log(noerr(() => a.b)); // 1
console.log(noerr(() => a.b.c)); // undefined
console.log(noerr(() => a.b.c.d)); // undefined
console.log(noerr(() => a.b.c())); // undefined

noerr(() => x); // ReferenceError: x is not defined

Preparation

Node ESModules & NPM

npm install noerr
import noerr from 'noerr';
Node CommonJS & NPM
npm install noerr
const { default: noerr } = require('noerr');
Browser & CDN
<script src="https://unpkg.com/noerr@latest"></script>
<script>
const noerr = NoErr.default;
</script>

Keywords