Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gabrielrufino/is-required
⚠️ Throws an error when an expected parameter is not defined
https://github.com/gabrielrufino/is-required
javascript npm
Last synced: 7 days ago
JSON representation
⚠️ Throws an error when an expected parameter is not defined
- Host: GitHub
- URL: https://github.com/gabrielrufino/is-required
- Owner: gabrielrufino
- License: unlicense
- Created: 2023-02-11T18:43:33.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-20T10:56:09.000Z (27 days ago)
- Last Synced: 2024-11-02T01:03:31.083Z (14 days ago)
- Topics: javascript, npm
- Language: JavaScript
- Homepage:
- Size: 696 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# isRequired
Throws an error when an expected parameter is not defined.
## Installing
```bash
npm i @gabrielrufino/is-required
```## Arguments
```js
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
```js
import { isRequired } from '@gabrielrufino/is-required'const object = {
a: 1
}const {
a = isRequired({ param: 'a' })
} = objectconsole.log(a) // 1
const {
b = isRequired({ param: 'b' })
} = object // Throws IsRequiredError
```