
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
hooks system for custom plugins
npm install hookpoint
Each hook triggers every added function in a loop.
SeriesHook. This hook simply calls every function added in a row.
LastOutHook. A bail hook allows exiting early. When any of the tapped function returns anything, the bail hook will stop executing the remaining ones.
Waterfall. A waterfall hook also calls each added function in a row. It passes a return value from each function to the next function.
All hooks allow exiting early. To exit early a method must be passed to the constructor for detecting this case.
All Hook constructors take one optional argument, which is a list of argument names as strings.
const hook = new SeriesHook<[string, number], boolean>();
The best practice is to expose all hooks of a class in a hooks property:
class HttpFile {
constructor() {
this.hooks = {
parse: new SeriesHook<[String, ParseContext], ParseResult>(),
replaceVariables: new WaterfallHook<[string, ReplaceVariableContext], string>()
};
}
}
Other people can now use these hooks:
const httpFile = new HttpFile();
httpFile.hooks.parse.addHook("javascript", (text, context) => addExecuteAction(text));
It's required to pass a id to identify the plugin/reason.
All Hooks offer an additional interception API:
httpFile.hooks.parse.addInterceptor({
beforeLoop: async function checkUserCancellation(
hookContext: models.HookTriggerContext<[models.ProcessorContext], boolean>
) {
const context = hookContext.args[0];
if (context.progress?.isCanceled?.()) {
log.trace('process canceled by user');
return false;
}
return true;
},
})
4.1.0 (2024-08-03)
FAQs
hooks system for custom plugins
The npm package hookpoint receives a total of 6,940 weekly downloads. As such, hookpoint popularity was classified as popular.
We found that hookpoint demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.