Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.
/ noerr Public archive

Safe property reference chaining without errors

License

Notifications You must be signed in to change notification settings

mpyw/noerr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>