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 🙏

© 2024 – Pkg Stats / Ryan Hefner

skyhook

v1.1.0

Published

A promise-based pub sub hub hook system for node

Downloads

28

Readme

skyhook

io.js compatibility node.js compatibility

NPM version Dependency Status Dev Dependency Status Code Climate Build Status Coverage Status

A Promise-based pub sub hub hook system for node.

Installation

npm install --save skyhook

Usage

// Normal example
var hooks = require('skyhook')();

hooks.register('init', function () {
  console.log('initializing');
});

hooks.trigger('init').then(function () {
  console.log('initialized');
  // console.logs the following:
  // initializing
  // initialized
});

// Real World example
var express = require('express');

hooks.register('middleware', function (app) {
  app.get('/user', function (req, res, next) {
    res.json({
      firstName: req.body.firstName,
      lastName: req.body.lastName
    });
  });
}, {once: true, weight: 1});

hooks.register('middleware', function (app) {
  app.use(express.static(__dirname + '/public'));
}, {once: true});

hooks.trigger('middleware', express()).then(function (app) {
  app.listen(8000);
});

Options

Constructor options

Below are the default options passed to the constructor.

var Skyhook = require('skyhook');
// You don't need the `new` keyword. It will create a new instance for you.
var hooks = new Skyhook({
  Promise: require('bluebird') // You can override the Promise implementation.
});

.register() options

The first parameter is the name of the hook you want to register to. The second is the method you want called. If you want to bind a specific context, you'll need to bind it manually with .bind(). It's only argument is the object that the hook was triggered with. If the argument is an object, any changes you make to the properties of the object will persist to the next call. If you get a string, a number, or other value that is passed by reference, then you must return the modified value if you wish your changes to be persisted.

This is chainable with multiple registers.

hooks.trigger('init', function () {}, {
  weight: 0, // Orders the hook methods in order of weight, smallest number going first
  once: false // Will only call the hook method once, no matter how many times the hook is called
});

.trigger() options

The first parameter is the name of the hook you wish to call. The second is options, but if you wish to expose any config object you wish to be exposed to other hooks, this is where you would put it. Note that it only accepts 1 parameter. This is to simplify your hooks. If you wish to expose more than one parameter to be changed, just create another hook.

The third parameter is an options object. It's only option is returnChange whose default value is true. When set to false, it will not accept values returned from a hook to modify the value. Note that if a parameter is passed by reference (such as an array or an object), then a hook can still modify properties on the passed object.

This method returns a promise with resolves to the modified (or un-modified) value that you passed (or didn't pass).

.triggerMultiple() options

triggerMultiple is the same as .trigger(), but the first argument accepts an array of hooks you want to call. The second parameter works like before, and it gets passed through all of the arguments passed.

Questions/Comments

PRs/Issues welcome!

License

MIT (see LICENCE)