A little javascript library for checking argument values
It takes time to add explicit conditions to your functions to check arguments and throw errors. The purpose of this library is to assist developers on writing efficiently and reliably those conditions.
Via NPM:
npm i check-arguments --save
Loading the library:
const { check } = require("check-arguments");
Now you can use it on your functions:
function foo(val){
check(val).isString().isNotBlank();
// The remaining source code
}
or
function foo(a, b){
check(a).isInt().isBetween(12, 20);
check(b).isString();
// The remaining source code
}
These are the list of predicates you may use
For isNumber()
:
isLessThan(max)
isLessThanOrEqualsTo(max)
isGreaterThan(min)
isGreaterThanOrEqualsTo(min)
isBetween(min, max)
inRange(min, max)
isPositive()
isNegative()
For isInt()
:
isEven()
isOdd()
For isString()
:
isNotBlank()
For isObject()
:
hasKey()
isEmpty()
Install the dependencies
npm install
Run the development enviroment
npm run dev
Feel free to access the discussions tab as you need
Contributions to the this project are very welcome! We can't do this alone! Feel free to fork this project, work on it and then make a pull request.
Licensed under the MIT license.
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).
However, if you get some profit from this or just want to encourage me to continue creating stuff, reach out to me if you want to do it.
Thanks!
❤️