Effortlessly empower your project with typed hooks, enabling you to easily construct a plugin API for your needs.
📦 Installation
npm install hooxs
📚 Usage
import { createHooks } from "hooxs";
interface RuntimeHooks {
"build:before": () => void;
"build:after": (files: string[]) => void;
// can either be registered inside the hooks object or registered at a later point
"config:load"?: (config: Record<string, unknown>) => void;
}
const hooks = createHooks<RuntimeHooks>({
"build:before": () => {
console.log("before build");
},
"build:after": (files) => {
console.log("after build", files);
},
});
// or initialize hooks at a later point
const hooks = createHooks<RuntimeHooks>();
hooks.on("config:load", (config) => {
console.log("config loaded", config);
});
await hooks.call("build:before");
const files = ["index.js", "index.css"];
await hooks.call("build:after", files);
📄 License
Published under MIT License.