Have ideas to improve npm?Join in the discussion! »

    check-arg-types

    2.0.0 • 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;
    }

    Install

    npm i check-arg-types

    DownloadsWeekly Downloads

    15

    Version

    2.0.0

    License

    ISC

    Unpacked Size

    18.5 kB

    Total Files

    11

    Last publish

    Collaborators

    • avatar