arg-typesdeprecated

runtime argument type checking

Usage no npm install needed!

<script type="module">
  import argTypes from 'https://cdn.skypack.dev/arg-types';
</script>

README

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.')
}