New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

arguard

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arguard

Function argument validator

latest
Source
npmnpm
Version
1.2.1
Version published
Weekly downloads
7
-22.22%
Maintainers
1
Weekly downloads
 
Created
Source

arguard

Function argument validator.

Throws an error if the argument being tested is of wrong type or doesn't meet specified criteria.

Usage

var arguard = require('arguard');

function foo(bar, baz, options){
	arguard.number(bar, 'bar');
	arguard.string(baz, 'baz').oneOf(['local', 'remote']);
	arguard.object(options, arguard.names.options);
}

API

FunctionThrows errof if
bool(arg, argName)typeof arg !== 'boolean'
object(arg, argName)typeof arg !== 'object' OR !arg
array(arg, argName)!Array.isArray(arg)
func(arg, argName)typeof arg !== 'function'
number(arg, argName)typeof arg !== 'number' OR Number.isNaN(arg)
number(arg, argName).positive()as above AND arg <= 0
string(arg, argName)typeof arg !== 'string'
string(arg, argName).oneOf(['str1', 'str2'])as above AND (arg != 'str1' AND arg != 'str2')
string(arg, argName).nonempty()typeof arg !== 'string' AND arg !== ''

arguard.maybe.number(..), arguard.maybe.string(..), arguard.maybe.bool(..), arguard.maybe.func(..) allow first argument to be undefined but otherwise behave as specified above.

arguard.names is an object with 3 keys, which holds strings for common arguments names:

{
	params: 'params',
	options: 'options',
	cb: 'cb'
}

Similar module: aproba

Keywords

argument

FAQs

Package last updated on 10 Jan 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