0.1.0 • Published 12 years ago

argtypes v0.1.0

Weekly downloads
8
License
-
Repository
github
Last release
12 years ago

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 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.