1.0.1 • Published 8 years ago
@f/switch v1.0.1
switch
A functional switch statement.
Like switch, but drops the switching arg, and passes subsequent args.
Installation
$ npm install @f/switch
Usage
var Switch = require('@f/switch')
Switch({
add: add,
subtract: subtract,
multiply: multiply,
default: add
})('add', 1, 1) // => 2
function add (arg1, arg2) {
return arg1 + arg2
}
API
switch(cases)
cases
- An object with keys as cases and values as the the function to call.
Returns: a function that switches on the first arg and calls matched function with subsequent args
License
MIT