Comparing version 1.1.0 to 1.1.1
{ | ||
"name": "call-hook", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Hook function calls with other functions", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
module.exports = function post (callee, preCall) { | ||
var aborted | ||
return function callHook () { | ||
var aborted | ||
var result = preCall.apply({ abort: abort }, arguments) | ||
if (aborted) return aborted.returnValue | ||
return callee.apply(undefined, Array.isArray(result) ? result : arguments) | ||
} | ||
function abort (returnValue) { | ||
aborted = { returnValue: returnValue } | ||
function abort (returnValue) { | ||
aborted = { returnValue: returnValue } | ||
} | ||
} | ||
} |
@@ -51,10 +51,7 @@ var test = require('tape'), | ||
test('pre hookedFunc returnValue is callee returnValue', function (t) { | ||
t.plan(1) | ||
t.plan(2) | ||
var returnValue = pre(callee, function () { | ||
return 'hi' | ||
})() | ||
t.equal(pre(callee, function () { return 'hi' })(), 42, 'returnValue = 42') | ||
t.equal(pre(callee, function () {})(), 42, 'returnValue = 42') | ||
t.equal(returnValue, 42, 'returnValue = 42') | ||
function callee () { | ||
@@ -79,1 +76,21 @@ return 42 | ||
}) | ||
test('pre abort does not prohibit subsequent calls', function (t) { | ||
t.plan(5) | ||
var showEvens = pre(callee, filterOdd) | ||
t.equal(showEvens(0), 0) | ||
t.equal(showEvens(1), undefined) | ||
t.equal(showEvens(2), 2) | ||
t.equal(showEvens(3), undefined) | ||
t.equal(showEvens(4), 4) | ||
function filterOdd (number) { | ||
if (number % 2 === 1) this.abort() | ||
} | ||
function callee (number) { | ||
return number | ||
} | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14017
193