{"library":"promised-hooks","title":"Promised Hooks","description":"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.","language":"javascript","status":"maintenance","last_verified":"Sat Apr 25","install":{"commands":["npm install promised-hooks"],"cli":null},"imports":["import hooks from 'promised-hooks'","import hooks from 'promised-hooks'; hooks.wrap(MyClass)","import hooks from 'promised-hooks'; MyClass.pre('method', fn)"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import hooks from 'promised-hooks';\n\nclass Service {\n  async fetch(id) {\n    return { id, data: 'original' };\n  }\n}\n\nhooks.wrap(Service);\n\nService.pre('fetch', async function() {\n  // this is the class instance\n  console.log('pre hook called');\n  // Override arguments: resolve with __override\n  return { __override: [42] };\n});\n\nService.post('fetch', async function(result) {\n  result.modified = true;\n  return result;\n});\n\nconst service = new Service();\nconst result = await service.fetch(1);\nconsole.log(result); // { id: 42, data: 'original', modified: true }","lang":"javascript","description":"Demonstrates wrapping a class, adding pre hook to override arguments, and post hook to modify the response.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}