rarity
Continuation tools for callbacks arity.
1 - Carry arguments
Here is some shitty code:
{ var aVar = 1; ;}
Here is some improved version, using rarity:
{ var aVar = 1; ;}
Arguments passed in the array will be carried between the first argument of the original callback (the error, in node convention) and all the others.
Documentation
rarity.carry(arrayOfArgumentsToAddBetweenErrorAndOriginal, cb)
If you pass something else than an array, it will be automatically wrapped in an array:
rarity.carry(value, cb)
=>rarity.carry([value], cb)
=>cb(err, value, ...arguments)
2 - Slice arguments
Did you ever find yourself writing shitty code such as this one:
;
To minimize the quantity of arguments sent over to your next function (async.waterfall
anyone?)
rarity
allow you to easily control this behavior:
// Generate a wrapper function around cb, only forwarding the first parameter.;
Documentation
rarity.slice(maxNumberOfArgumentsToForward, cb)
Without rarity
var async = ; async;
With rarity
var async = ;var rarity = ; async;
3 - Pad arguments
When using some shitty-backported lib, for instance factory-lady
, you'll need to pad your queries with a first additional argument representing a fake error, making it compatible with all the node ecosystem.
The following code:
;
Will become, using rarity:
// Wraps cb with a new function, sending null as the first argument.;
Documentation
rarity.pad(arrayOfArgumentsToPad, cb)
4 - Carry and slice
Specific use case, combining rarity.carry
and rarity.slice
:
The following code:
{ var aVar = 1; ;}
Will become, using rarity:
{ var aVar = 1; ;}
Documentation
rarity.carryAndSlice(arrayOfArgumentsToAddBetweenErrorAndOriginal, maxNumberOfArgumentsToForward, cb)
Installation
npm install rarity
You're done. Now go write some shitty code.
Why the shitty name?
rarity
is short for reduce arity
.
Also, arity was already created on npm.