@slimio/arg-checker
v0.2.1
Published
SlimIO Argument Checker
Downloads
32
Readme
arg-checker
SlimIO Argument Checker. This package is inspired by ow to retrieve the callsites but doesn't include any built-in predicates.
Requirements
- Node.js v10 or higher
Why ?
- No built-in predicates/validation
- No browser support (only Node.js).
Getting Started
This package is available in the Node Package Repository and can be easily installed with npm or yarn.
$ npm i @slimio/arg-checker
# or
$ yarn add @slimio/arg-checkerUsage example
const argc = require("@slimio/arg-checker");
const is = require("@slimio/is");
function sayHello(name, age) {
argc(name, [is.string, is.symbol]); // <-- Array stand for "OR" condition
argc(age, is.number);
}
sayHello("fraxken", 24);
// => No error
sayHello(true);
// => ArgumentError: 'name' doesn't match his predicate(s)API
Check if arg match his predicates.
const logValidInput = (input) => {
argc(input, is.number, (num) => num > 10 && num < 20);
// ...predicates are executing as && condition.
console.log(input);
}
logValidInput(15);
// => No Error
logValidInput(50);
// => ArgumentError: 'input' doesn't match his predicate(s)Roadmap
- Custom Error message ?
- Improve predicates detection ?
Dependencies
|Name|Refactoring|Security Risk|Usage| |---|---|---|---| |callsites|⚠️Major|Low|Get V8 call stack traces| |clean-stack|Minor|Low|Clean the stack trace generated by Errors|
License
MIT
