Hookified provides a robust solution for integrating event emitting and middleware-style hooks into JavaScript and TypeScript applications. Currently at version 2.1.1, the library maintains an active release cadence, with frequent updates addressing performance, type improvements, and feature enhancements. Key differentiators include its dual support for asynchronous and synchronous middleware hooks, serving as a simple yet powerful EventEmitter replacement. It offers comprehensive support for ESM and CJS module systems, along with TypeScript types and compatibility with Node.js 20+ environments, including browser support via CDN. The library boasts a lean footprint with no external package dependencies and a small size (around 250KB), focusing on fast and efficient execution, as evidenced by its benchmarks. Features like WaterfallHook for data transformation, robust error handling, options for enforcing hook naming conventions (enforceBeforeAfter), and built-in mechanisms for managing deprecated hooks (deprecatedHooks, allowDeprecated) further distinguish its capabilities.
npm install hookifiedVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates instantiating Hookified, registering standard and WaterfallHooks, emitting and listening to events, and processing data through the hook lifecycle.
Update all instances of `this.logger` to `this.eventLogger`.
Migrate usage to `throwOnHookError` in the constructor options or instance property.
Ensure an 'error' event listener is always registered, or explicitly set `throwOnEmptyListeners: false` in the `Hookified` constructor options if you want to suppress this behavior.
Review the migration guide from v1 to v2 on the project's GitHub page for details on adapting custom hook implementations or extending `Hookified`.
Prefix all custom hook names (e.g., `beforeSave`, `afterValidation`) or set `enforceBeforeAfter: false` if this naming convention is not desired.
Use `.hook()` for general hook execution. Only use `.hookSync()` when strictly needing to process only synchronous handlers.
Change references from `myInstance.logger` to `myInstance.eventLogger` or `this.eventLogger`.
Rename your hook to `beforeMyCustomHook` or `afterMyCustomHook`, or disable the enforcement by passing `{ enforceBeforeAfter: false }` to the `Hookified` constructor.Refactor your module to use ESM `import { Hookified } from 'hookified';` or use dynamic imports `import('hookified').then(module => new module.Hookified());` if you must remain in CJS.Add an 'error' event listener: `myInstance.on('error', (err) => { console.error('Caught error:', err); });` or set `new Hookified({ throwOnEmptyListeners: false })` to suppress this behavior.No dependency data recorded yet.