0.2.1 • Published 5 years ago

@slimio/arg-checker v0.2.1

Weekly downloads
290
License
MIT
Repository
github
Last release
5 years ago

arg-checker

version Maintenance MIT

SlimIO Argument Checker. This package is inspired by ow to retrieve the callsites but doesn't include any built-in predicates.

Requirements

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-checker

Usage 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

NameRefactoringSecurity RiskUsage
callsites⚠️MajorLowGet V8 call stack traces
clean-stackMinorLowClean the stack trace generated by Errors

License

MIT