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

jector

v0.1.0

Published

Simple, unobtrusive dependency injection

Readme

jector

Simple, unobtrusive dependency injection.

Simple

Jector uses constructor injection to provide dependencies by mapping a function's argument names to values in the injection context. It provides powerful IoC constructs with a minimalist API.

Unobtrusive

Jector is designed to work along side your existing classes and module architecture. It doesn't require that you conform to a prescribed means of declaring modules or classes, relying instead on constructor argument names. (And even those can remain intact by using the minsafe alternative to dependency declaration).

Usage

Context Creation

jector.context(namespace)

Create a new injection context by providing a namespace. If the namespace has already been declared, the existing context is returned.

JavaScript:

var jector = require('jector');
var context = jector.context('myNamespace');
console.log(context.namespace); // output 'myNamespace'

CoffeeScript:

jector = require('jector')
context = jector.context('myNamespace')
console.log(context.namespace) # output 'myNamespace'

Singletons

context.singleton(dependencyName, constructorMethod)

singleton() declares a named Singleton. The constructorMethod (which may be a class constructor or any other function) is invoked the first time the dependency is requested, and the instance is retained.

JavaScript:

function Slab() {
  this.id = Math.random();
}

function Frame(slab) {
  this.slab = slab;
}

context.singleton('slab', Slab);
context.singleton('frame', Frame);

var frame = context.get('frame');
var slab = context.get('slab');

console.log(frame.slab === slab); // output 'true'

CoffeeScript:

class Slab
  constructor: -> @id = Math.random()

class Frame
  constructor: (@slab) ->

context.singleton('slab', Slab)
context.singleton('frame', Frame)

frame = context.get('frame')
slab = context.get('slab')

console.log(frame.slab is slab); # output 'true'

Factories

context.factory(dependencyName, factoryMethod)

factory() declares a factory method that will be invoked any time the named dependency is requested.

JavaScript:

function Slab() {
  this.id = Math.random();
}

function Frame(slab) {
  this.slab = slab;
}

context.singleton('slab', Slab);
context.factory('frame', Frame);

var frame1 = context.get('frame');
var frame2 = context.get('frame');

console.log(frame1 === frame2); // output 'false'
console.log(frame1.slab === frame2.slab); // output 'true'

CoffeeScript:

class Slab
  constructor: -> @id = Math.random()

class Frame
  constructor: (@slab) ->

context.singleton('slab', Slab)
context.factory('frame', Frame)

frame1 = context.get('frame')
frame2 = context.get('frame')

console.log(frame1 is frame2) # output 'false'
console.log(frame1.slab is frame2.slab) # output 'true'

Values

context.value(dependencyName, instance)

value() registers an existing instance as a named dependency for injection.

JavaScript:

function Slab() {
  this.id = Math.random();
}

function Frame(slab) {
  this.slab = slab;
}

var slab = new Slab()
context.value('slab', slab);
context.factory('frame', Frame);
var frame = context.get('frame');

console.log(frame.slab === slab); // output 'true'

CoffeeScript:

class Slab
  constructor: -> @id = Math.random()

class Frame
  constructor: (@slab) ->

slab = new Slab()
context.value('slab', slab)
context.factory('frame', Frame)

frame = context.get('frame')

console.log(frame.slab is slab) # output 'true'

Minsafe Dependency Declaration

Jector relies on constructor argument names to intuit an object's dependencies. Minification can obliterate those names. If you plan to minify your code, define a _needs Array on your constructor (or function), and this will be used instead of the function's argument names.

JavaScript:

function Slab() {
  this.id = Math.random();
}

function Frame(s) {
  this.slab = s;
}
Frame._needs = ['slab'];

var slab = new Slab()
context.value('slab', slab);
context.factory('frame', Frame);
var frame = context.get('frame');

console.log(frame.slab === slab); // output 'true'

CoffeeScript:

class Slab
  constructor: -> @id = Math.random()

class Frame
  constructor: (s) ->
    @slab = s
Frame._needs = ['slab']

slab = new Slab()
context.value('slab', slab)
context.factory('frame', Frame)
frame = context.get('frame')

console.log(frame.slab is slab) # output 'true'