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 🙏

© 2024 – Pkg Stats / Ryan Hefner

depjector

v1.0.1

Published

this is a dependency injector for node 4.x <

Downloads

9

Readme

#depjector

this is a dependency injector for node 4.x <

##Installation use npm for the installation, simple do

npm install depjector --save

i am still testing in a bigger app, to find bugs/changes to fix before going up to 1.0

##Dependencies and services in depjector there is 2 kinds of Dependencies, the first is a normal commonJS module, the second one is a service, this is also a normal module, but it get a parameter that tell depjector that it is a service.

you can added settings for depjector in the form of a extra property to the module.exports object with the name __dependency.

ex.

const MyDependency = function(dep1, dep2) {
    return {
        one: () => {
        ...
        },
        
        two: () => {
        ...
        },
        
        public: (app) => {
        }
    };
}

module.exports = MyDependency;

// the extra property
module.exports.__dependency = {
    // if you need to rename the dependency name
    name: "overwriteTheName",
    // the services this module supports
    service: ["service:one", "service:two", "routes:public"],
    // overwrite the dependencies if you want to name the parameters some thing else.
    args: ["overwriteDependency1", "dep2"],
    // if a module is autowired it will be use raw as the dependency, good for config or other objects like db connection.
    autowired: true
};

services is useful, because all the modules with the same service will be call in serial and this is useful for ex. express.js's routes, you can call a service with the express app object and get all the routes fill out without require files. this is also useful if you want to add a plugin to you app, just down in the files, and all the files is load next time you restart the app and all the new routes is added.

##API

###create the object

const Depjector = require("depjector");
const depjector = new Depjector();

###index dependency you can use addByPath, addDependencies, addDependency to add dependencies to the store, then use one of the get methods to get them back out. all the index methods is returning promises

indexPath is use for index all in a folder, it take a path(string) as parameter

depjector.indexPath("./lib").then((countOfLoadedDependencies) => {
});

indexDependencies take a array of dependencies, and loop them and call indexDependency with each.

depjector.addDependencies([
    {path: "./lib/some.js"},
    {name: "more", path:"./justIn.js"},
    {path: "./services/routes.js", service: ["routes:public"]}
]).then(() => {
});

addDependency is use for adding a dependency to the dependency store

depjector.addDependency({name: "more", path:"./justIn.js"}).then(() => {
});

###get dependency getDependency, executeService

getDependency is creating a object of the type of the dependency and return it, if the dependency has it's own dependencies then they will be auto injected.

const more = depjector.getDependency("more");

executeService runs service with the name in the first parameter and pass the rest in to the service, it return the results from all the module created for this call.

const results = depjector.executeService("routes:public", arg1, arg2);

##TODO

  • better docs
  • fix bug in the unittests, so i can get 100% coverage (it is now but the modules i am using got a bug)