Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

call-hook

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

call-hook - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

2

package.json
{
"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
}
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc