2.1.0 • Published 8 months ago

or-throw v2.1.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
8 months ago

or-throw

Returns the value if truthy or throws an error.

import { orThrow } from 'or-throw';

let foo = null;

orThrow(foo) // throws `new Error()`
orThrow(foo, 'error message') // throws `new Error('error message')`

foo = 1

orThrow(foo) // returns 1
import { orThrowDeferred } from 'or-throw';

let foo = null;

orThrowDeferred(foo) // throws `new Error()` after a setTimeout with delay set to 0
orThrowDeferred(foo, 'error message') // throws `new Error('error message')` after a setTimeout with delay set to 0

foo = 1

orThrowDeferred(foo) // returns 1

Install

You can get or-throw via npm.

npm i or-throw
2.1.0

8 months ago

2.0.0

8 months ago

1.0.0

8 months ago