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

    argtypes

    0.1.0 • Public • Published

    ArgTypes

    Filters incoming arguments so that they match specified types and can be optional.

    Examples

    var fn = argtypes(
        'b', 'f',
        function( useThing, cb ){
        
        }
    );
    var fn = argtypes(
        [ '?b', true ], [ '?f', function(){} ], [ '?as', [ 1, 2, 3 ] ]
       , function( aBool, aFn, aAry ){
     
    } )
     
    fn()                         // arguments = [ true,  function(){}, [   1,   2,   3 ] ]
    fn( false, ['a', 'b', 'c'] ) // arguments = [ false, function(){}, [ 'a', 'b', 'c' ] ]
    fn( new Foo(), 'foo' )       // arguments = [ true,  FOO instance, 'foo'             ]

    Usage

    • ? -- value is optional

    Followed by (one or more of):

    • . -- Any value is allowed
    • a -- Array
    • b -- Boolean
    • f -- Function
    • i -- Integer
    • n -- Numeric
    • s -- String
    • o -- Object ( {} )
    • C -- Class instance. Definition: [ 'C', Foo ] or [ '?C', Foo, new Foo( 'a', 'b', 'c' ) ] If the default value is used in this case, a new object is created as: new Foo( fooObj ) and it is up to the constructor to handle this case properly.

    Keywords

    none

    Install

    npm i argtypes

    DownloadsWeekly Downloads

    2

    Version

    0.1.0

    License

    none

    Last publish

    Collaborators

    • avatar