@small-tech/required
Version:
Add required argument checking to your functions.
45 lines (27 loc) • 1.2 kB
Markdown
Fail-fast on missing required arguments in JavaScript using default values that throw.
[](https://ar.al/2020/03/23/fail-fast-on-missing-required-arguments-in-javascript-using-default-values-that-throw/)
```sh
npm i @small-tech/required
```
```js
const required = require('@small-tech/required')
function foo (puppy = required('puppy')) {
// It’s safe to use puppy from here on.
}
// Output: Error: Missing argument (puppy).
foo()
```
- Throws errors on missing required arguments.
- 100% code coverage ;P
- Yes, you could just write this yourself.
[](https://small-tech.org) is a tiny, independent not-for-profit.
We exist in part thanks to patronage by people like you. If you share [our vision](https://small-tech.org/about/#small-technology) and want to support our work, please [become a patron or donate to us](https://small-tech.org/fund-us) today and help us continue to exist.
© 2020 [Aral Balkan](https://ar.al), [Small Technology Foundation](https://small-tech.org).
[](https://opensource.org/licenses/MIT)