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

nodeject

v0.5.1

Published

A simple dependency injection module for JavaScript. Works as both a node.js module and as a browser module. CommonJS compatible.

Downloads

39

Readme

#Usage

The container is simple. You use define and resolve to manage all dependencies.

Build Status

##Todo

  • Cyclical dependency detection.
  • Better lifetime management, singleton flag is nice, but there are more than just transient and singleton lifetimes.
  • Browser script to be used in AMD/CommonJS/POJS(Plain Old Javascript).

###Example

var container = new Nodeject();

container.define({ name : "module1", type : require("module1") })
         .define({ name : "module2", type : require("module2"), deps: ["module1"] });

 var module2Impl = container.resolve("module2");

###define

//Uses the options pattern to configure an entity.
function define(options) { ... };

container.define({
        name : "module1",           // Must be a unique name in the container.
        type : MyType,              // Can be a Prototype, Power Constructor, String, or Array
        deps : ["module2", "m2"],   // Array of modules configured or to be configured in the container.
        singleton : false           // If a singleton is needed, pass true, default is false.
    });

###resolve

// Resolves with a single module name.
function resolve(moduleName) { ... };

var module1 = container.resolve("moduleName");

###wrap Nodeject now supports wrapping of global entities along with resolving a field off of another bound entity.

// Wrapping a global or other entity
container.define({ name : '$',
    wrap : {
        resolve : jQuery
    }
});
var $ = container.resolve('$');

// Binding a field to a resolvable name
container.define({ name : "app",
    type : function (){
        return {
            bus : {
                on : function (){ "..."; }
            }
        };
    }
});
container.define({ name : 'bus',
    wrap : {
        resolve : 'bus',
        context : 'app'
    }
});
var bus = container.resolve('bus');

###categories Categories are a way of configuring multiple items and resolving them under a single name. This is helpful when configuring controllers or presenters where initialization needs to occur in bulk.

// Configure the container with entities having a common category
container
  .define({
    name : "module1",
    type : MyType,
    category : "category1"
  })
  .define({
    name : "module2",
    type : MyOtherType,
    category : "category1"
  });

var entities = container.resolve({ category : "category1" });
assert.ok (entities[0] instanceof MyType);          // asserts true
assert.ok (entities[1] instanceof MyOtherType);     // asserts true

var entities = container.resolve({ category : "category1", format : "literal" });
assert.ok ("module1" in entities);                  // asserts true
assert.ok ("module2" in entities);                  // asserts true

###compound keys

// In order to enable compound keys feature you have to specify compoundKeys/delimiter option
var container = new Nodeject({
  singleton: true,
  compoundKeys: {
    delimiter: '::'
  }
});

// Configure the container with two identical names in two different categories
container
  .define({
    name : "main",
    category : "moduleOne",
    type : MyType
  })
  .define({
    name : "main",
    category : "moduleTwo",
    type : MyOtherType
  });

var moduleOneMain = container.resolve('moduleOne::main');
// what is the same as
moduleOneMain = container.resolve({ category: 'moduleOne', name: 'main' });
// and now you can use compound keys when you define deps
container.define({
  name: 'aggr',
  type: AggrType,
  deps: ['moduleOne::main', 'moduleTwo::main']
});