arguer
Version:
Normalizes arguments for JavaScript functions with optional arguments and provides optional typing.
38 lines (34 loc) • 864 B
JavaScript
var arguer = require('./arguer.js');
//function test (a, b, c) {
// var args = arguer(arguments, ['a', {name: 'b', optional: true}, 'c']);
// console.log(args);
// if (args instanceof Error)
// console.log('is error');
//}
//function test (a, b, c) {
// if (arguments.length < 3) {
// c = b;
// b = undefined;
// }
// console.log({a: a, b: b, c: c});
//}
//function test (a, b, c) {
// var args = arguer(arguments, ['a', {name: 'b', optional: true, nType: 'string'}, {name: 'c', optional: true, type: 'string'}]);
// console.log(args);
//}
function test (a, b, c)
{
var args = arguer.apply(['a', 'b', 'c'], arguments);
// var args = arguer(arguments, ['a', 'b', 'c']);
// if (args instanceof Error)
// {
// console.log(args.message);
// return;
// }
// else
// {
// console.log(args);
// }
}
for (var i = 0; i < 100000; i ++)
test('hello', 'world', 3);