check-arg-types

2.0.1 • Public • Published

check-arg-types

Build Status

Pass in arguments and an array of the expected types (as string descriptions) and throw if they don't match. Simple to adopt and only ~320 bytes.

function test(a, b, c) {
  check(arguments, ['string', 'number', 'boolean']);
  return a + b + c;
}

test('hey', 1, 'true'); // Uncaught TypeError: Expected 'boolean' given 'string' for argument at index 2

Allow multiple types

// `a` can be a string or number
function example(a, b) {
  check(arguments, [['string', 'number'], 'number']);
  return a + b;
}

Can skip checking for some arguments

// `b` can be any type
function example(a, b, c) {
  check(arguments, ['string', '-any', 'numbers');
  return a + b + c;
}

Package Sidebar

Install

npm i check-arg-types

Weekly Downloads

13

Version

2.0.1

License

ISC

Unpacked Size

18.9 kB

Total Files

11

Last publish

Collaborators

  • staydecent