Given a method, return a function that accept
this
as last argument
The ideal complement for functional javascript, you get function that use same semntic as ramda library.
This example uses unthis
to transform the match
method
of String prototype.
Original match
method has one argument, the RegExp
to match with.
this
context for the method must be a String to match against.
unthis
return a function with two arguments:
it pass the first to original method RE argument,
and uses the second argument as this
context.
import unthis from 'unthis';
const match = unthis(String.prototype.match);
const matchFinalS = match(/s$/);
console.log(matchFinalS("words") !== null); // --> true
console.log(matchFinalS("lollo") !== null); // --> false
console.log(match(/^w/, "words") !== null); // --> true
Given an object method, unthis return a function that
accept all original arguments plus one.
It forward all arguments to the method, and uses the
last argument as this
context for it.
Parameters
method
Function The original method to transform
Returns Function The transformed function
Given an object, unthisAll apply unthis
to all its
methods, and return an object containing all resulting functions.
By default, all object methods are extracted. Otherwise, you can also specify which method to include or exclude.
Parameters
object
Object The object containing methods to transform.$1
Object (optional, default{}
)$1.exclude
(optional, default[]
)$1.include
(optional, defaultnull
)
exclude
Array An array containing name of methods to transform.include
Array An array containing name of methods to exclude from transform.
Returns Object An object with all transformed methods.
With npm installed, run
npm install --save unthis
MIT