1.0.4 • Published 9 years ago

mixedargs v1.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

MixedArgs

This is a simple tool for creating function that accepts multiple combination of arguments. This can be used in NodeJS or browser.

Installation

NodeJS:

$ npm install mixedargs --save

Browser:

$ bower install mixedargs --save

Usage

//In node only
var mixedargs = require('mixedargs');

var showError = function() {

    var args = mixedargs(arguments);

    if( args.when(['String', 'Number']) ) {
        //Message, ErrorCode
    }
    else if( args.when(['String', 'String']) ) {
        //Message, ErrorType
    }
}

And async mode

var showError = function() {

    var args = mixedargs(arguments);

    args.when(['String','Number'], function(message, code){
        //do something
    });

    args.when(['String','Object'], function(message, data){
        //do something
    });

}