0.1.2 • Published 1 year ago

patable v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Migrated, see @vzt7/unhook.


patable

npm version npm downloads Github Actions

Can be used to create hooks for plugins.

🦭 Why ?

  • ✅ Get all returns of each hook.
  • ✅ Types friendly, specify the hook type you want.
  • ✅ Almost likes tapable, more light & clear.

📦 Installation

# with pnpm
pnpm install patable

# with yarn
yarn add patable

# with npm
npm install patable

⚡️ Usage

Almost refer to tapable.

  • AsyncParallelBailHook
  • AsyncParallelHook
  • AsyncSeriesBailHook
  • AsyncSeriesHook
  • AsyncSeriesWaterfallHook
  • TODO: Sync hooks
import { AsyncSeriesHook } from 'patable';

const hook = new AsyncSeriesHook();

hook.tap('say', () => {
  console.log('Hello World');
});

hook.tap('scream', () => {
  console.log('Hello World!!!');
});

hook.dispatch();

// Hello World
// Hello World!!!

Only the dispatch method is different implementation for each hook, and all hooks follow the usage below.

import { AsyncSeriesHook } from 'patable';

const hook = new AsyncSeriesHook<(arg0: string) => string>();

hook.tap({ name: 'say', once: true }, (arg0) => {
  console.log('Hello World');
});

hook.tap('scream', (arg0) => {
  console.log('Hello World!!!');
  return 'screaming';
});

hook.tap({ name: 'smile', stage: -10 }, async (arg0) => {
  return 'smiling';
});

hook.tap({ name: 'silent', before: 'scream' }, (arg0) => {
  console.log(arg0);
});

hook.dispatch('Anyone else').then((result) => {
  console.log(result); // ['smiling', undefined, undefined, 'screaming'];
});

// Hello World
// Anyone else
// Hello World!!!

💻 Development

  • Clone this repository
  • Enable Corepack using corepack enable (use npm i -g corepack for Node.js < 16.10)
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm dev

License

Published under WTFPL.

           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                   Version 2, December 2004

Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

 0. You just DO WHAT THE FUCK YOU WANT TO.
0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.1

1 year ago