check-arguments v0.1.2
A little javascript library for checking argument values
Why
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.
How Do I Install It?
Via NPM:
npm i check-arguments --save
How to I Use It?
Loading the library:
const { check } = require("check-arguments");
Now you can use it on your functions:
function foo(val){
check(val).isString().isNotBlank();
}
or
function foo(a, b){
check(a).isInt().isBetween(12, 20);
check(b).isString();
}
Predicates
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 Developers
Install the dependencies
npm install
Run the development enviroment
npm run dev
Questions or Suggestions
Feel free to access the discussions tab as you need
Contribute
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.
License
Licensed under the MIT license.
Donate
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!
❤️