Wraperizer
chainable wraperizer for a function
Examples
const Wraperizer = defaultconst fn = a;const wraperizer = fn;wraperizer$ === fn; // true
$
Pointer to fn
function
Type: function
add
Adds wrapper as a method into instance.
fn
is bound as the first argument of a wrapping function
Parameters
Examples
const fn = argA;const wraperer = fn;wrapererWraperizeradd'increment' + incconst incremented2 = wraperer$const incremented5 = wraperer$ === 4; // true === 7; // true
Returns Function.Wraperizer
del
Removes method from instance
Parameters
name
string
Returns Function.Wraperizer
bare Wraperizer (without wrappers) can be obtained via require('wraperizer/source/Wraperizer');
Build-in wrappers usage
Examples
const fn = a;const wraperizer = fn;const wrapered = wraperizer$;; // Promise<3>
after
Postprocesses fn
results with wrapper
Parameters
Examples
const fn = a + bconst fnAfter = a * 21 2; // Promise<6>
Returns function (): Promise
before
Preprocesses arguments with wrapper
before fn
Parameters
Examples
const fn = a + 1const fnBefore = a * b1 2; // Promise<7>
Returns function (): Promise
bottleneck
Creates queue for fn
with concurrency limitation
Parameters
Returns function (): Promise
bunching
Creates function to bunching data of multiply bunching function result invokes
Parameters
handler
function (Array<arguments>): any function for processing `bunch` of datachecker
function (resolve: function) function to invoke handlerseparator
function function to parse result fromhandler
into chunks
Examples
let timer;const invoke = ; for let i = 0; i < 3; i++ ;
Returns function (): Promise function to set chunk of data to process bunchly
compose
Compose functions
Examples
const fn1 = a * 2;const fn2 = a + 1;const fn3 = a ** 2;2; // 10;
Returns function
curry
Curries function
Parameters
Examples
const fn = a + b + c;const curried = ;; // 6;2 3; // 6;3; // 6;23; // 6;
Returns function
length
Returns function with given length
(required for curry)
Parameters
Examples
const fn = a + b;fnlength; // 2length; // 5
Returns function
limit
Limits fn invokes
Parameters
Examples
const fn = a + b;const limited = ;; // 3; // 3; // undefined
Returns (function (): any | undefined)
memo
Map based memoization for function
Parameters
Returns function function with memoization
nextTick
Postpones invoke of fn
to nextTick
Parameters
fn
function
Returns function (): Promise
pipe
Pipe functions
Examples
const fn1 = a * 2;const fn2 = a + 1;const fn3 = a ** 2;2; // 25
Returns function
promisify
Wrap function with a Promise and call it in async manner
Parameters
fn
function
Examples
const fn = a + b;1 2; // Promise<3>
Returns function (): Promise
promisifyCb
Wrap node-style function with a Promise
Parameters
Examples
{ ;} 1; // Promise<2>
Returns function (): Promise function returns Promise for fn
invoking
redefine
Creates function wrapper with self-redefine ability
Parameters
fn
function function which will be invoke on next call of returned functioninit
Examples
const fn3 = a ** b;const fn2 = a * b;const fn1 = a + b;const wrapped = ;; // 5; // 6; // 8; // 8
Returns function (any, redefiner: redefiner) init - function which will invoke fn
with adding redefiner
callback as last argument
redefiner
Set function for next call
Type: Function
Parameters
fn
function function for next call
Returns function fn
retry
Retries fn
call if error occurs
Parameters
fn
functionretries
number (optional, default1
)handler
function (optional, default(error,argsObject)->argsObject
)
Returns function (): Promise
throttle
Creates function throttling wrapper
Parameters
fn
functionstay
function (): Boolean function which define mustfn
be invoked or not (optional, default()->false
)
Examples
const wrapped = ;; // 3; // undefined; // 3
Returns function
throttleAsync
Creates function throttling wrapper
Parameters
fn
functionstay
function (): Boolean function which define mustfn
be invoked or not (optional, default()->false
)
Returns function (): Promise
timeout
Delay function invoke
Parameters
fn
function function which will be invoke on next call of returned functioninit
delay
number delay interval in milliseconds
Examples
const wrapped = ;; // Promise<2> will resolve in 100 milliseconds
Returns function (): Promise