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

mooring

v2.0.0

Published

Simple, stable, easy to use system for pre/post hooks in NodeJS

Downloads

6

Readme

Mooring

Build Status Coverage Status bitHound Overalll Score

Born from a desire to have an API / hooks system that:

  • Has a small API surfice
  • Is easy to understand
  • Has a data flow that is immutable
  • Lets pre hooks manipulate the data going into a hooked method
  • Lets post hooks manipulate the data coming out from a hooked method
  • Not have the hooks stored on the prototype but rather in a seperate object

Credit to the kareem & grappling-hook projects for their insight and the inspiration they provided (also some code ;).)

API Spec

before hooks

Before hooks are called before a given function executes. They receve in their method sig all the params the hooked method receves and can augment them.

It runs before hooks with a synchronous API

    
        // Here, false marks the hook as synchronous
        hooks.before('cook', false, function(food) {
            // food == 'burger'
            assert.equal('burger', food);

            // your code here
            // synchronous hooks can NOT augment params passed to hooked methods
        });

        var cook = hooks.createHook('cook', function(food) {
            // This is the method you want to hook
            done();
        });

        // When you call the now-hooked method, the hooks will be called
        cook('burger');
    

It also runs before hooks with an asynchronous API

Asynchronous is the default

    
        hooks.before('cook', function(food, next) {

            assert.equal('burger', food);
            // food = burger
            food = 'hotdog';
            // your code here

            next(food);
        });

        var cook = hooks.createHook('cook', function(food) {
            // food = hotdog
            assert.equal('hotdog', food);
            done();
            // This is the method you want to hook
        });

        // When you call the now-hooked method, the hooks will be called
        cook('burger');
    

It can run multipe before hooks

    
        var count1 = 0;
        var count2 = 0;

        hooks.before('cook', function(next) {
            ++count1;
            next();
        });

        hooks.before('cook', function(next) {
            ++count2;

            next();
        });
        var cook = hooks.createHook('cook', function() {
            assert.equal(1, count1);
            assert.equal(1, count2);
            done();
        });
        cook();
    

after hooks

It runs after hooks with a synchronous API

    
        // Here, false marks the hook as synchronous
        hooks.after('cook', false, function(feelings) {
            // feelings == 'I LOVE BURGERS'
            assert.equal('I LOVE BURGERS', feelings);
            done();
        });

        var cook = hooks.createHook('cook', function(food) {

            return 'I LOVE BURGERS';
        });

        // When you call the now-hooked method, the hooks will be called
        cook('burger');
    

It also runs after hooks with an asynchronous API

Asynchronous is the default

    
        hooks.after('cook', function(feelings, feelings2, next) {
            // feelings == 'I LOVE BURGERS'
            // feelings2 == 'I hate fries'
            assert.equal('I LOVE BURGERS', feelings);
            assert.equal('I hate fries', feelings2);

            next('Burgers are OK');
        });

        var cook = hooks.createHook('cook', function(food, callback) {
            callback('I LOVE BURGERS', 'I hate fries');
        });

        // When you call the now-hooked method, the hooks will be called
        cook('burger', function(feelings, feelings2) {
            // feelings == 'Burgers are OK'
            // feelings2 == 'I hate fries'
            assert.equal('Burgers are OK', feelings);
            assert.equal('I hate fries', feelings2);
            done();
        });
    

It can run multipe after hooks

    
        var count1 = 0;
        var count2 = 0;

        hooks.after('cook', function(next) {
            ++count1;
            next();
        });

        hooks.after('cook', function(next) {
            ++count2;

            next();
        });
        var cook = hooks.createHook('cook', function(cb) {
            cb();
        });
        cook(function() {
            assert.equal(1, count1);
            assert.equal(1, count2);
            done();

        });
    

call hooks

It lets you call a hook without first defining it

    
        // Here, false marks the hook as synchronous
        hooks.after('cook', false, function(feelings) {
            // feelings == 'I LOVE BURGERS'
            assert.equal('I LOVE BURGERS', feelings);
            done();
        });

        // first param is the hook name, next is an array of arguments, next is a flag for is the call immutable and lastly is your hooked method/code
        hooks.callHook('cook', ['burger'], true, function(food) {

            return 'I LOVE BURGERS';
        });