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

useify

v0.0.13

Published

`Useify` is a middleware implementation that extends objects

Downloads

2

Readme

Useify


Useify is a middleware implementation that extends objects.

Example

// var Useify = require( "Useify" ),
//   should = require( "should" );

var MyClass = function () {
  this.hasInitialised = false;
  this.value = 0;
}

MyClass.prototype.init = function () {
  this.hasInitialised = true;
  this.middleware( "postInit", function () {
    this.execute();
  } );
};

MyClass.prototype.execute = function () {
  this.middleware( function ( _sum ) {

    this.hasInitialised.should.be.true;
    should( _sum ).equal( 22 );
    _done();

  }, 1, 2 );
}

// `Useify` the class
Useify( MyClass );

// Adds the first middleware function.
MyClass.use( function ( _one, _two, _next ) {

  // The context `this` is a reference to the context class. In this example it is `myClass`
  var aValue = myClass.value + _one + _two;

  // Trigger the callback when this functions tasks are complete. Pass a dynmaic amount of
  // arguments to the next function.
  _next( aValue );

} );

// Adds the second middleware function. Note that the first argument is the paramater from the
// previous middleware function. The last argument should always be the callback to the next
// middleware function.
MyClass.use( function ( _three, _next ) {

  _next( _three, 4 );

} ).use( function ( _three, _four, _next ) { // `use` can be chained

  _next( _three + _four + 5 );

} );

// This is a named middleware function. By default, middleware functions are named "all". This
// will give you the ability to add multiple middleware injection points.
MyClass.use( "postInit", function ( _next ) {

  this.value = 10;
  _next();

} );

// Runs the middleware queue of functions. The last argument of `run` is a callback that is 
// triggered after the queue is emptied.

var myClass = new MyClass();

myClass.init();

API


Useify(object)

Add Useify to an object

object.use([params...], [fn])

Adds a middleware function to the queue. A dynamic amount of params can be passed from the previous middleware function. The callback must be the last paramater. use is chainable.

object.middleware([params...], [fn])

Runs the queue of middleware functions in the order they were added. A dynamic amount of params can be passed from the previous middleware function. The callback must be the last paramater.