Simple type checking and such for functions in JavaScript. Built to either be a Node.JS module or webpage include.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Pass a function to def.
Internal name is taken from that name, and it's suggested to use one.
Argument typing and optionalness is taken from the argument name:
1) name //no type checking, required
2) Type_name //type checking (Type is a class like String or Number), required
3) name$ //no type checking, optional
4) Type_name$ //type checking, optional

How to use:
var def = require("def.js"); //If using from Node.JS
var myFunc = def(function myFunc(prefix,Number_body$,String_suffix$){
	// Defaults:
	body = defarg(this.body,1);
	suffix = defarg(this.suffix,"");
	return "" + (prefix + body) + suffix;

Example executions and results:
> myFunc(":)");
> myFunc(12);
> myFunc(3,"abc");
Function "myFunc" argument 1 must be of type Number
> myFunc(3,1,"abc");
> myFunc("a",1,"abc");