🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

arg-types

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arg-types

runtime argument type checking

0.0.10
latest
Source
npm
Version published
Weekly downloads
2
-71.43%
Maintainers
1
Weekly downloads
 
Created
Source

arg types Build Status js-standard-style

A very simple module to do runtime argument type checking of functions.

Usage

Installation:

Use yarn or npm:

$ [sudo] npm install --save arg-types

Example:

The very contrived example below would stop "33" being returned by the function.

var argTypes = require('./')

// define your function signature, the next line returns a function
// which expects an `arguments` object
var helloSignature = argTypes(['number', 'number', 'number'])

function hello (a, b, c) {
  helloSignature(arguments) // add this line as the first one in the target function

  return a + b + c
}

try {
  hello(1, 2, '3')
} catch (ex) {
  assert(ex.message === 'Expected "number" but got "string" at argument 3.')
}

Keywords

arguments

FAQs

Package last updated on 21 Jan 2017

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