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

hook-up

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hook-up

Create your own hook api with 2-dimensional hooks - better than events or simple hooks

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by22.22%
Maintainers
1
Weekly downloads
 
Created
Source

hook-up

Create your own hook api with 2-dimensional hooks - better than events or simple hooks.

Install

npm install --save hook-up

Usage

hookUp = require("hook-up")
// hookUp(obj:Object, options:Object)
someObj = {}
hookUp(someObj)
// adds a function:
// registerHooks(names:String | Array of Strings)
someObj.registerHooks("start")
// adds functions 
// to add a hook
// [name].register({prio: (optional) Number, cb: Function})
// to call all hooks
// [name].execute(obj)
// to delete all hooks
// [name].clear()
someArg = {}
someHook = async (arg) =>
  // this == someObj
  // arg == someArg
  // do something async
someObj.start.register(someHook)
someObj.start.register({prio: 2, cb: someHook}) // bigger prio gets called first
// hooks with the same prio get called simultaneously
await someObj.start.execute(someArg)
Options
Nametypedefaultdescription
prefixArray or String-to add a namespace for all hooks
registerStringregistername of the register prop, can be empty
executeStringexecutename of the execute prop, can be empty

Note, that only one of register or execute can be empty

Example for custom API

hookUp = require("hook-up")
someObj = {}
hookUp(someObj,{prefix:["before","after"], register: "call", execute:""})
someObj.registerHooks("start")
// will result in the following api for hooks:
someObj.before.start.call(someHook)
someObj.after.start.call(someOtherHook)
// to execute
await someObj.before.start(someArg)

License

Copyright (c) 2017 Paul Pflugradt Licensed under the MIT license.

FAQs

Package last updated on 01 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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