npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

node-hooker

v2025.9.7-3

Published

A powerful and flexible hook system for Node.js, inspired by the WordPress actions and filters API.

Readme

node-hooker

A powerful and flexible hook system for Node.js, inspired by the WordPress actions and filters API. This package provides a simple yet effective way to create extensible and decoupled architectures in your JavaScript applications.

Version GitHub license    GitHub stars    GitHub forks    GitHub watchers    GitHub followers Hire Me

[ It is designed to be cross-platform, supporting modern ES2015+ environments as well as vanilla JavaScript setups. ]

Features

  • Full WordPress Hook API compatibility: Implements the vast majority of WP hook functions.

  • Actions (do_action): Create points in your code where other functions can be executed.

  • Filters (apply_filters): Create points in your code where data can be modified.

  • Priority-based execution: Control the order in which callbacks are executed.

  • Hook Inspection: Check if hooks exist, how many times they've run, and what's currently running.

  • Easy to use: A simple and intuitive API.

  • Zero dependencies: Lightweight and self-contained.

Installation

You can install package via-

npm install

This is the standard way to install any Node.js package-

npm install node-hooker

Or-

Yarn install

Yes — Yarn can install npm packages because it uses the same npm registry under the hood (equivalent to npm install node-hooker)-

yarn add node-hooker

Test

After installation, you can run tests from the terminal using-

npm test

Quick Start

✅ NodeJS

const hooker = require('node-hooker');

// --- ACTIONS ---
// 1. Register a function for an action hook
function myActionCallback(arg1, arg2) {
    console.log(`Action running! Args: ${arg1}, ${arg2}`);
    console.log(`Currently doing action: ${hooker.current_action()}`);
}
hooker.add_action('app_init', myActionCallback, 10, 2);

// 2. Trigger the action hook
console.log('Doing action...');
hooker.do_action('app_init', 'user_id_123', { setting: 'on' });
console.log(`'app_init' has run ${hooker.did_action('app_init')} time(s).`);


// --- FILTERS ---
// 1. Register a function for a filter hook
function myFilterCallback(text) {
    return text.toUpperCase();
}
hooker.add_filter('format_title', myFilterCallback);

// 2. Trigger the filter hook and use the modified value
let title = 'Hello World';
title = hooker.apply_filters('format_title', title);
console.log(title); // Output: HELLO WORLD

OR

✅ Browser Usage (UMD)

This library can be used directly in the browser. A UMD (Universal Module Definition) bundle is provided in the dist folder, which is also available via CDN.

1. Include via CDN

You can add node-hooker to your project by including the following script tag. It's recommended to use the minified version for production.

<!-- Regular -->
<script src="https://cdn.jsdelivr.net/npm/node-hooker/dist/node-hooker.umd.min.js"></script>

<!-- Minified -->
<script src="https://cdn.jsdelivr.net/npm/node-hooker/dist/node-hooker.umd.js"></script>

2. Example Usage

Once included, the library will be available under the global variable Hooker.

<!DOCTYPE html>
<html>
<head>
    <title>node-hooker Browser Example</title>
</head>
<body>
    <h1>Check the console for output!</h1>

    <script src="https://cdn.jsdelivr.net/npm/node-hooker/dist/node-hooker.umd.min.js"></script>

    <script>
        // The library is now available on the window.Hooker object
        console.log(Hooker);

        // Add an action
        Hooker.add_action('app_loaded', function() {
            console.log('The application has loaded!');
        });

        // Trigger the action
        Hooker.do_action('app_loaded');
        // Console Output: The application has loaded!

        // Use a filter
        const originalText = "hello browser";
        const filteredText = Hooker.apply_filters('format_text', originalText, (text) => text.toUpperCase());
        
        console.log(filteredText); 
        // Note: Filters require a callback to be added first to have an effect.
        // Let's add one now.
        Hooker.add_filter('format_text', (text) => text.toUpperCase());
        const trulyFilteredText = Hooker.apply_filters('format_text', originalText);
        console.log(trulyFilteredText);
        // Console Output: HELLO BROWSER
    </script>
</body>
</html>

Preview

✅ NodeJS

node test.php

OR

✅ Browser (UMD)

▶ Open Live Preview


API Reference

1. Registering Hooks

| Function | Purpose | | --- | --- | | add_action(hook, callback, priority, args) | Attach a function to an action hook. | | add_filter(hook, callback, priority, args) | Attach a function to a filter hook. |

2. Triggering Hooks

| Function | Purpose | | --- | --- | | do_action(hook, ...args) | Trigger an action hook (run all attached callbacks). | | do_action_ref_array(hook, args_array) | Same as do_action(), but pass arguments as an array. | | apply_filters(hook, value, ...args) | Trigger a filter hook, passing $value through each callback. | | apply_filters_ref_array(hook, args_array) | Same as apply_filters(), but arguments are passed as an array. |

3. Removing Hooks

| Function | Purpose | | --- | --- | | remove_action(hook, callback, priority) | Remove a previously added action callback. | | remove_filter(hook, callback, priority) | Remove a previously added filter callback. | | remove_all_actions(hook, priority) | Remove all callbacks for a specific action hook (or priority). | | remove_all_filters(hook, priority) | Remove all callbacks for a specific filter hook (or priority). |

4. Inspecting Hooks

| Function | Purpose | | --- | --- | | has_action(hook, callback = false) | Check if a function is hooked to an action (or if any callbacks exist). | | has_filter(hook, callback = false) | Check if a function is hooked to a filter (or if any callbacks exist). | | did_action(hook) | Returns how many times an action has run. | | current_action() | Get the name of the currently running action hook. | | current_filter() | Get the name of the currently running filter hook. | | doing_action(hook = null) | Check if a specific action (or any action) is currently running. | | doing_filter(hook = null) | Check if a specific filter (or any filter) is currently running. |

Advanced Usage

✅ Custom Instances

While the singleton is convenient, you can create isolated instances of the Hooker class for separate event buses.

const myInstance = new Hooker();

myInstance.add_action('my_hook', () => console.log('Hello from my instance!'));
myInstance.do_action('my_hook');

Files

Files structures/ tree

node-hooker/
├── lib/
│   └── Hooker.js
│   └── Hook.js
├── dist/
│   └── node-hooker.umd.js
│   └── node-hooker.umd.min.js
├── test.js
├── browser-test.html
├── package.json
├── README.md
└── CHANGELOG.md

License

This extensible codes is licensed under the MIT License. Copyright (c) 2025 by Mamedul Islam.

See the LICENSE file for more details.


Author & Hire Me

This extensible codes was created and is maintained by Mamedul Islam.

As a passionate web developer with experience in creating interactive and user-friendly web components. Currently available for freelance projects or full-time opportunities.

Helping businesses grow their online presence with custom web solutions. Specializing in WordPress, WooCommerce, and Shopify. Building modern, responsive, and high-performance scalable websites with custom made plugins, codes, customizations.

Hire Me


Show Your Support

If you find this extension useful, please consider giving it a star on GitHub! Your support helps motivate further development and improvements.

GitHub stars  

If you found this project helpful, give it a ⭐ on GitHub!