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

nojector

v0.3.0

Published

Node Parameter Injection

Readme

#Nojector A small realtively simple way to do parameter injection in node. Mostly for web applications. It looks at the parameter names, and tries to resolve them with a resolver. Really take a look at mers for a better idea of why and how to use it. The unit tests might give some ideas also.

Built in resovlers:

  • query - query string values.
  • session - session values.
  • body - body values.
  • params - Parameters.
  • args - additional arguments.
  • require - requires a module.

##Usage ###Basic

        var nojector = require('nojector').nojector;
        
        var conf = nojector({
            //custom resolvers
            resolvers: {
                async: function (ctx, settings, pos, param) {
                    var obj = {};
                    //pos is the positional argument.
                    obj[param] = ctx.args[pos];
                    var p = promise();
                    setTimeout(function () {
                        //using mpromise, it has a funny resolve.
                        p.resolve(null,obj);
                    }, 100);
                    return p;
                }
            }
        });
        //method you want to inject
        var a = function (async$user) {
            return async$user;
        }
        conf.resolve(a, {}, null, 2).then(function (val) {
        //    val.should.have.property('user', 2);
            done();
        });

###Express context

var a = {

   stuff:function(session$user){
//        do something with session$user;

   }

}
app.get('/stuff', function(req,res,next){

nojector.resolve(a.stuff, req).then(function(response){
  //do something with response;
  next();
}, next);

##Invoke Nojector also allows you to navigate object graphs, executing functions along the way. The basics are.

Its arguments are

  • obj - The object to decend.
  • path (optional) - a slash delimited string or an array of strings.
  • ctx (optional) - A context object
  • advice (optional) - a function that is used for controlling flow it will recieve * str -> the current array * obj -> the curent object * next -> a callback. * bv -> the next value to be evalated

*args... whatever else args to pass into the function.


    var obj = {
        array:[1,2,3,4,5]
    }

    invoker.invoke(obj, 'array/0').then(function (v) {
            v.should.eql(1)
            done();
        })

It can go more deeply

var obj = {

    stuff: [
        {a: 1},
        {b: 2},
        {
            c: {
                f: function () {
                    return 1;
                }
            }
        },
        {_id: 'abc', c: 1}
    ]
}

 invoker.invoke(obj, 'stuff/2/c/f').then(function (ret) {
        ret.should.eql(1);
  });

It will also inject arguments


var obj = {
    func: function (str) {
        return {
            abc: str,
            def: function (s, s2) {
                var ret = {}
                ret[str] = s2;
                return ret;
            }
        }
    }
}

invoker.invoke(obj, 'func/def/a', {}, null, 'a', 'b').then(function (ret) {
            ret.should.eql('b');
            done();
 });

##Optional Resolvers To make this look like a true DI framework, there are a couple of optional resolvers.

  • Alias - Allows for an unqualified method, resolve to a qualified method.
   var inject = nojector({
        resolvers: {
            args: optional.anyAlias({
                user: 'query$user',
                bob: function (query$qa) {
                    var p = promise();

                    setTimeout(p.resolve.bind(p, null, query$qa), 100);

                    return p;
                },
                aliased: 'user'
            }),
            bean: optional.bean({
                stuff: function (bob) {
                    return bob;
                }
            })
        }
    }), ctx = {
        query: {
            user: 'joe',
            qa: 'stuff'
        }
    };
    inject.resolve(function(user){
    //should have 'joe' as the value.

    });
  • Bean - This resolver is basically a statically scoped resolver.