mpyw / noerr

Safe property reference chaining without errors

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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>

About

Safe property reference chaining without errors

License:MIT License


Languages

Language:JavaScript 100.0%