shuffler
shuffler
lets you swap around the order of a function's arguments by index.
Installation
Using NPM:
$ npm install shuffler
Or as a component:
$ component install hughsk/shuffler
Usage
shuffler
takes a function as its first argument and returns a second function to determine the new argument order. Take this example:
var shuffle ={console};// ['a', 'b', 'c', 'd']args = 3 2 1 0// ['d', 'c', 'b', 'a']
You can pass a falsey non-numerical value to mute it, i.e. that argument will always be null
:
// ['a', 'b', 'c', 'd']args = 3 2 false 0// ['d', 'c', null, 'a']
Or a truthy non-numerical value to just use the default argument:
// ['a', 'b', 'c', 'd']args = 3 2 true 3// ['d', 'c', 'c', 'd']
By default, any extra arguments will still be used. You can disable this by
passing the carryon
option as false.
// ['a', 'b', 'c', 'd']args = 1 1// ['b', 'b', 'c', 'd']args = 1 1// ['b', 'b']