Last Updated: February 25, 2016
·
797
· zvictor

optional parameters, default values and type-checking for your JavaScript method signatures

ArgueJS is a new JavaScript library that allows you to delightfully extend your methods's signatures with optional parameters,
default values and type-checking.

example

Let's suppose we want to rewrite the well known method range from underscorejs.

Note that documentation says its method signature is range([start], stop, [step]). With ArgueJS we could type just this way:

function range(){ 
  arguments = __({start: [Number, 0], stop: Number, step: [Number, 1]})

  for(var i = arguments.start; i < arguments.stop; i += arguments.step)
    console.log(i);
}

Repl:

>>> range(3)
 0
 1
 2
>>> range(3, 5)
 3
 4
>>> range(0, 5, 2)
 0
 2
 4

Take a look at the documentation for more.