arg-check
arg-check is a lightweight library to help developers catch bugs before they skitter in by making sure the right types of arguments are being passed into functions and methods.
It takes two arguments: (1) an argument you've passed into a function declaration, and (2) the type you expect that argument to be. It couldn't be easier:
let argCheck = ; let { ; ; return a + b;}; ; // 7 ; // TypeError: Expected argument to be of type "number" but instead received type "string"
Getting Started
Step 1
In the terminal:
$ npm install arg-check
Step 2
In path/to/my/rad/app/or/whatever/app.js:
let argCheck = ;
Step 3
Really, that's it. Start arg-checking!
Supported Argument Types
Note all argument types are lowercase strings.
'null'
'undefined'
'string'
'number'
'boolean'
'array'
'object'
argCheck also supports custom class types:
{ thisname = attributesname; } let rachael = name: 'Rachael' ; let { ; return personname;}; ; // 'Rachael' // TypeError: Expected argument to be of type "person" but instead received type "object"
Note again that the expected class name will be a lowercase string.
Contributing
We'd love contributors and feedback! We are currently at 100% test coverage and that's the way we like it. Hit us up and let's make this thing even better.
License
arg-check is released under the MIT License