JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2487344
  • Score
    100M100P100Q197200F
  • License MIT

Event and Middleware Hooks

Package Exports

  • hookified
  • hookified/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hookified) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Hookified

Event and Middleware Hooks for Your Libraries

tests GitHub license codecov npm npm

Features

  • Emit Events via Emittery
  • Middleware Hooks with data passing
  • ESM and Nodejs 20+
  • Maintained on a regular basis!

Installation

npm install hookified --save

Usage

this is primarily a library for creating hooks and middleware for your own libraries. Here is an example of a class that is extended using hookified.

import { Hookified } from 'hookified';

class MyClass extends Hookified {
  constructor() {
    super();
  }

  async myMethod() {
    await this.emit('before:myMethod');
    // do something
    await this.emit('after:myMethod');
  }

  async myMethod2() Promise<any> {
    let data = { some: 'data' };
    // do something
    await this.hook('before:myMethod2', data);
    // do something
    await this.hook('after:myMethod2', data);
    return data;
  }
}