{"name":"hookified","version":"1.2.0","description":"Event and Middleware Hooks","type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.cjs","import":"./dist/index.js"}},"engines":{"node":">=20"},"scripts":{"test":"xo --fix && vitest run --coverage","test:ci":"xo && vitest run --coverage","clean":"rimraf ./dist ./coverage ./site/dist","build":"rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean","website:build":"docula build","website:serve":"docula serve","prepare":"npm run build"},"keywords":["hooks","eventemitter","eventemitter3","middleware","events","hooks","event-hooks","hook-system","event-driven","event-emitter","hook-handlers","middleware","emit","event-management","before-after-hooks","event-listeners","custom-hooks","hook-utilities","typescript-hooks"],"repository":{"type":"git","url":"git+https://github.com/jaredwray/hookified.git"},"author":{"name":"Jared Wray","email":"me@jaredwray.com"},"license":"MIT","bugs":{"url":"https://github.com/jaredwray/hookified/issues"},"homepage":"https://github.com/jaredwray/hookified#readme","devDependencies":{"@vitest/coverage-v8":"^2.1.1","docula":"^0.9.1","rimraf":"^6.0.1","tsup":"^8.3.0","typescript":"^5.6.2","vitest":"^2.1.1","xo":"^0.59.3"},"_id":"hookified@1.2.0","gitHead":"3b0bf69b4c351c5ad381ab961a6c552824fcf186","_nodeVersion":"20.17.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-32q0JrtZRAdCGeEa8IcBz4iABsrP4UiDrbFj/WADL1VyNHRvHdGs8MrYvaIZWMzbff1xdS3Tw8kBt6YvcSL7jQ==","shasum":"ab4f39e667c69eb877082cdc48f9d3decad125fb","tarball":"http://registry-npm.ywwl.com/hookified/download/hookified-1.2.0.tgz","fileCount":7,"unpackedSize":15963,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC75SSdqWsfdndnBCONdaobHITtRYRQg6JEewVzCiiQQQIhAIeRLX1tQe5i0DnS63pbXvXO0dAoVHQW+1pa6uVmSkqM"}],"size":4248,"noattachment":false,"key":"/hookified/-/hookified-1.2.0.tgz"},"_npmUser":{"name":"jaredwray","email":"me@jaredwray.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hookified_1.2.0_1727882490384_0.507117956171208"},"_hasShrinkwrap":false,"readme":"<img src=\"site/logo.svg\" alt=\"Hookified\" height=\"400\" align=\"center\">\n\n# Event Emitting and Async Middleware Hooks\n\n[![tests](https://github.com/jaredwray/hookified/actions/workflows/tests.yaml/badge.svg)](https://github.com/jaredwray/hookified/actions/workflows/tests.yaml)\n[![GitHub license](https://img.shields.io/github/license/jaredwray/hookified)](https://github.com/jaredwray/hookified/blob/master/LICENSE)\n[![codecov](https://codecov.io/gh/jaredwray/hookified/graph/badge.svg?token=nKkVklTFdA)](https://codecov.io/gh/jaredwray/hookified)\n[![npm](https://img.shields.io/npm/dm/hookified)](https://npmjs.com/package/hookified)\n[![npm](https://img.shields.io/npm/v/hookified)](https://npmjs.com/package/hookified)\n\n## Features\n- Simple replacement for EventEmitter\n- Async Middleware Hooks for Your Methods\n- ESM / CJS with Types and Nodejs 20+\n- Maintained on a regular basis!\n\n## Installation\n```bash\nnpm install hookified --save\n```\n\n## Usage\nThis was built because we constantly wanted hooks and events extended on libraires we are building such as [Keyv](https://keyv.org) and [Cacheable](https://cacheable.org). This is a simple way to add hooks and events to your classes.\n\n```javascript\nimport { Hookified } from 'hookified';\n\nclass MyClass extends Hookified {\n  constructor() {\n    super();\n  }\n\n  async myMethodEmittingEvent() {\n    this.emit('message', 'Hello World'); //using Emittery\n  }\n\n  //with hooks you can pass data in and if they are subscribed via onHook they can modify the data\n  async myMethodWithHooks() Promise<any> {\n    let data = { some: 'data' };\n    // do something\n    await this.hook('before:myMethod2', data);\n\n    return data;\n  }\n}\n```\n\nYou can even pass in multiple arguments to the hooks:\n\n```javascript\nimport { Hookified } from 'hookified';\n\nclass MyClass extends Hookified {\n  constructor() {\n    super();\n  }\n\n  async myMethodWithHooks() Promise<any> {\n    let data = { some: 'data' };\n    let data2 = { some: 'data2' };\n    // do something\n    await this.hook('before:myMethod2', data, data2);\n\n    return data;\n  }\n}\n```\n\n## API\n\n### .onHook(eventName, handler)\n\nSubscribe to a hook event.\n\n### .removeHook(eventName)\n\nUnsubscribe from a hook event.\n\n### .hook(eventName, ...args)\n\nRun a hook event.\n\n### .hooks\n\nGet all hooks.\n\n### .getHooks(eventName)\n\nGet all hooks for an event.\n\n### .clearHooks(eventName)\n\n### .on(eventName, handler)\n\nSubscribe to an event.\n\n### .off(eventName, handler)\n\nUnsubscribe from an event.\n\n### .emit(eventName, ...args)\n\nEmit an event.\n\n## .listeners(eventName)\n\nGet all listeners for an event.\n\n## .removeAllListeners(eventName)\n\nRemove all listeners for an event.\n\n## .setMaxListeners(maxListeners: number)\n\nSet the maximum number of listeners and will truncate if there are already too many.\n\n## Development and Testing\n\nHookified is written in TypeScript and tests are written in `vitest`. To run the tests, use the following command:\n\nTo setup the environment and run the tests:\n\n```bash\nnpm i && npm test\n```\n\nTo contribute follow the [Contributing Guidelines](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCT.md).\n\n## License\n\n[MIT & © Jared Wray](LICENSE)\n\n\n\n\n","publish_time":1727882490567,"maintainers":[{"name":"jaredwray","email":"me@jaredwray.com"}],"_cnpm_publish_time":1727882490567,"dist-tags":{"latest":"3.1.0"}}