README
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(){} ], [ '?a', [ 1, 2, 3 ] ]
, function( aBool, fAn, aAry ){
} )
fn(); // arguments = [ true, function(){}, [ 1, 2, 3 ] ]
fn( false, ['a', 'b', 'c'] ) // arguments = [ false, function(){}, [ 'a', 'b', 'c' ] ]
Usage
?
-- value is optional
Followed by:
.
-- Any value is alloweda
-- Arrayb
-- Booleanf
-- Functioni
-- Integern
-- Numerics
-- Stringo
-- 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.