UNPKG

@small-tech/required

Version:

Add required argument checking to your functions.

45 lines (27 loc) 1.2 kB
# @small-tech/required Fail-fast on missing required arguments in JavaScript using default values that throw. [Read the blog post.](https://ar.al/2020/03/23/fail-fast-on-missing-required-arguments-in-javascript-using-default-values-that-throw/) ## Install ```sh npm i @small-tech/required ``` ## Use ```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() ``` ## Features - Throws errors on missing required arguments. - 100% code coverage ;P - Yes, you could just write this yourself. ## Like this? Fund us! [Small Technology Foundation](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. ## Copyright © 2020 [Aral Balkan](https://ar.al), [Small Technology Foundation](https://small-tech.org). ## License [MIT](https://opensource.org/licenses/MIT)