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

dijection

v0.1.1

Published

Dijection is a small javascript dependency injection library that relies on parsing the result of the passed in function.toString().

Downloads

9

Readme

#Dijection Dijection is a small javascript dependency injection library that relies on parsing function parameter lists for dependency declaration.

By default, Dijection uses the '_' prefix to check for dependencies:

var DI = require("dijection")(); //or window.Dijection();

DI.register("serviceA", {
    method: function() {
        return 1;
    }
});

DI.register("serviceB", DI(function(_serviceA) {
    return _serviceA.method() + 1;
}));

var injected = DI(function(_serviceB) {
    return _serviceB() + 2;
});

console.log(injected()); //outputs 4!

Dijection uses the '$' prefix to inject all dependencies with that name.

var DI = require("dijection")(); //or window.Dijection();

DI.register("service", {
    method: function() {
        return 1;
    }
});

//you can override a dependency simply by re-registering it.
DI.register("service", {
    method: function() {
        //overriden dependencies are still available via the $ prefix.
        return 5;
    }
});

var injected = DI(function(_service, $service) {
    console.log(_service.method()); //5, the most recently registered service
    var sum = 0;
    $service.forEach(function(service) {
        sum += service.method();
    });
    
    console.log(sum); //6!
});

Any parameter not prefixed with '_' or '$', will be assumed to be a function parameter for the returned injected method:

var DI = require("dijection")(); //or window.Dijection();

DI.register("serviceA", {
    method: function() {
        return 1;
    }
});

DI.register("serviceB", DI(function(_serviceA) {
    return _serviceA.method() + 1;
}));

//injected dependencies will be omitted from the parameter list for the returned function
var injected = DI(function(parameter, _serviceB, anotherParam, yetAnother) {
    //any parameters that are not passed in when the injected function is called will be passed as undefined.
    return _serviceB() + parameter + anotherParam + yetAnother;
});

console.log(injected(5, 1)); //outputs 8!

##Context Files

Setup your context file:

var DI = require("dijection")(); //or window.Dijection();

//make sure to return your dependency injection container as your module output
//  Pass an object into DI, where each property value pair is a dependency.
module.exports = DI({
    "escapedDatasource": DI(function(_datasource, appender) {
        return escape(_datasource + (appender ? appender : ""));
    }),
    "datasource": "https://github.com/john-holland"
});

Use the dependency injection container exposed by your context file:

var DI = require("./context");

DI(function(_escapedDatasource, _datasource) {
    console.log(_datasource + " " + _escapedDatasource("/dijection"));
})();
//outputs: https://github.com/john-holland https%3A//github.com/john-holland/dijection

##Minification support

To support javascript minification, a parameter shim can be used to inform Dijection of what needs to be done for the function's parameter list. The upside of shimming the parameter list is being able to use it to alias dependency names -- the downside is that the order of the shim parameter list and the function parameter list must be the same.

var DI = require("dijection")(); //or window.Dijection();

//this is the same as the example above, but using shims.
DI.register("serviceA", {
    method: function() {
        return 1;
    }
});

DI.register("serviceB", DI(["serviceA"], function(service) {
    return service.method() + 1;
}));

//The same prefixes are used for the parameter shim, along with non-prefixed parameters 
//  creating the partial function.
var injected = DI(["param", "_serviceB", "param", "param"], function(parameter, shimmedService, anotherParam, yetAnother) {
    //note that _serviceB is aliased "shimmedService" and does not need a prefix 
    //  since the shim provides the '_' prefix to let dijection know it should be injected.
    return shimmedService() + parameter + anotherParam + yetAnother;
});

console.log(injected(5, 1)); //outputs 8!