@gabrielrufino/is-required
v1.0.20
Published
Throws an error when an expected parameter is not defined
Downloads
31
Readme
isRequired
Throws an error when an expected parameter is not defined.
Installing
npm i @gabrielrufino/is-required
Arguments
import { isRequired } from '@gabrielrufino/is-required'
function add(
a = isRequired({ param: 'a' }),
b = isRequired({ param: 'b' })
) {
return a + b
}
add(1, 1) // Returns 2
add() // Throws IsRequiredError
add(1) // Throws IsRequiredError
Destructuring assignment
import { isRequired } from '@gabrielrufino/is-required'
const object = {
a: 1
}
const {
a = isRequired({ param: 'a' })
} = object
console.log(a) // 1
const {
b = isRequired({ param: 'b' })
} = object // Throws IsRequiredError