Package Exports
- @slimio/arg-checker
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@slimio/arg-checker) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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
argc(arg: any, ...predicates: (argc.predicate | argc.predicate[])[]): void
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