Lightweight middleware utility that adds pre and post hooks to any function returning a Promise. Version 3.1.1 is the current stable release, last updated several years ago with no active development. It allows wrapping classes, functions, or objects to intercept Promise-returning methods, with support for argument overriding and post-hook response modification. Different from general middleware libraries like Express or Koa, it focuses specifically on Promise-based async flows and integrates hooks directly into existing classes or objects without requiring a framework.
npm install promised-hooksVerified import paths — ran on the pinned version, not inferred.
Demonstrates wrapping a class, adding pre hook to override arguments, and post hook to modify the response.
Ensure __override provides the exact arguments expected by the original method, either a single value or an array of arguments.
Design post hooks to chain properly; consider not using __override in post hooks unless you intend to discard previous responses.
Always call hooks.wrap(MyClass) before adding any pre/post hooks.
Add hooks.wrap(MyClass) before MyClass.pre('method', fn).Ensure every hook function returns a Promise (or is async).
Use { __override: ... } pattern correctly; if you don't need override, resolve with undefined or a simple value.No dependency data recorded yet.