unthis v1.1.0
unthis
Given a method, return a function that accept
thisas last argument
The ideal complement for functional javascript, you get function that use same semntic as ramda library.
Usage
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); // --> trueAPI
unthis
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
methodFunction The original method to transform
Returns Function The transformed function
unthisAll
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
objectObject The object containing methods to transform.$1Object (optional, default{})$1.exclude(optional, default[])$1.include(optional, defaultnull)
excludeArray An array containing name of methods to transform.includeArray An array containing name of methods to exclude from transform.
Returns Object An object with all transformed methods.
Install
With npm installed, run
npm install --save unthisSee Also
License
MIT