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 🙏

© 2026 – Pkg Stats / Ryan Hefner

graceland

v0.1.7

Published

A Dependency Injection container with soul

Readme

Graceland

Installing the library

In order to install this library all you need to do is:

npm install graceland --save-dev

Graceland has no dependencies other than those used to test the framework.

Adding Graceland to your project

Require Graceland register a library and a factory, start Graceland and use your api:

var graceland = require( 'graceland' );

graceland.register({
   id: 'fs',
   lib: require( 'fs' )
});

graceland.register({
   id: 'myFactory',
   factory: function( fs ) {

      // Do something with fs 
      function _doImportantFileSystemThing() {
         ...
      }

      return {
         doFsThing: _doImportantFileSystemThing
      }
   }
});

// Start Graceland
graceland.play();

// Get your factory
var myFactory = graceland.get( 'myFactory' );

// Do important file system thing
myFactory.doFsThing();

Entity Registration

There are three different types of entities that can be registered with Graceland:

Factories

  • When registered with Graceland, Factories are used to create an instance and that instance is what is injected into to other factories. There are two optional functions one can define on the instance returned by the factory:
    • init - runs before the instance creation and can be used for further runtime initialization of the factory instance.
    • destroy - runs before Graceland exits and can be used for teardown of the factory instance.
    • Example:
graceland.register({
   id: 'myFactory',

   // Inject fs and otherFactoryInstance
   factory: function( fs, otherFactoryInstance ) {

      // Do something
      function _doWork() {
         ...
      }

      return {
         doWork: _doWork,
         init: function() { // Do init },
         destroy: function() { // Do teardown } 
      }
   }
});

Libraries

  • Libraries are usually third party objects like fs or http. Graceland does nothing to these entities except pass them in. There is an optional 'prep' function you can define in the configuration object you create for the register function that will be executed before being injected.
    • Example:
graceland.register({
   id: 'fs',
   lib: require( 'fs' ),
   prep: function( fs ) {
      // Do Something to prep fs
      return fs;
   }
});

Values

  • Values are simple strings, objects or numerical values that one my want to inject into factories for configuration.
    • Example:
graceland.register({
   id: 'importantValue',
   value: { 
      username: 'user', 
      password: 'pwd' 
   }
});

Starting Graceland

When all the entities are registered, a call to:

graceland.play();

will start the application.

Why this is better

Unit Testing

Unit tests are hard enough to write, injecting libraries into your code makes mocking a lot easier.

var graceland = require( 'graceland' );

graceland.register({
   id: 'fs',
   lib: jasmine.createSpyObj( "mockFs", [ "readdir" ] );
});

graceland.register({
   id: 'myFactory',
   factory: require( "myFactory" )
});

describe( "Testing myFactory", function() {

   it( "Will use the injected file system library", function() {
      graceland.get( 'myFactory' ).doFsThing();
      expect( graceland.get( 'fs' ).readdir ).toHaveBeenCalled();
   });

});

Using Graceland, one can avoid re-defining require or doing other shifty things to test their code.

Running tests

To run a test suite execute:

grunt