Socket
Book a DemoInstallSign in
Socket

@slimio/arg-checker

Package Overview
Dependencies
Maintainers
6
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@slimio/arg-checker

SlimIO Argument Checker

0.2.1
latest
Source
npmnpm
Version published
Maintainers
6
Created
Source

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

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

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

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

License

MIT

Keywords

arg

FAQs

Package last updated on 19 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.