method-inject
A simple system for injecting and transforming methods
Installation
yarn add method-inject
npm install --save method-inject
Usage
To use method-inject, it's as simple as calling it on a method:
const inject = ; // Transform the first argument and prepend '[INFO] ' to itconst log = ; ;// => [INFO] Hello, there!
There are several methods, the rest of which are shown below:
const inject = ;const someObject = { console; }; // Hmm, we've been getting `NaN` in the console from someObject.buggedMethod, let's check it out:someObjectbuggedMethod = ;// Note that we passed someObject as the second parameter to inject, indicating that the method should be bound to that object. // Problem code:someObject;// => buggedMethod called with the following args: [ 'ERRORS' ]// => NaN
const inject = ; const db = internal: life: 42 { return thisinternalkey || default; }; if processenvDB_VERBOSE dbget = ; // Assuming DB_VERBOSE=true:console;// => DB::GET(key=life,default=-1) -> 42// => The meaning of life is 42
const inject = ; const multiply = { return a * b;}; const multiplyAndSquare = ; // (2 * 3) * (2 * 3) = 6 * 6 = 36console;// => 36
Methods can also be chained indefinitely:
const inject = ; const multiply = a * b;const addOne = x + 1;const square = x * x; const verboseComplexMath = ; console;// => COMPLEX_CALC -> 441// => 441