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

ambria

v1.0.2

Published

node dependency injector

Downloads

5

Readme

Ambria

A easy to use dependency injector for NodeJS application. To work, Ambria need you to develop your module in a particular way (quite similar to an angular controller)

Installation

npm install ambria

Features

  • "Automatic" dependency injection (you have to write a bit of code)
  • Automatic binding

Quick exemple

here's a quick exemple of how to use Ambria and what should you change in your application to make it work.

A random node module :

"use strict";

let ambria = require('ambria');

module.exports = 
    // Call ambria.module function to register this has a new module.
    ambria.module(
        'one', //This module name. Other module can use him by this name
        [
            // A dependency name. Note that lodash has not been imported here. 
            // This is mandantory, but obfuscation will break your app if you don't
            'lodash', 
            function(lodash) {
        
                function assingIn(){
                    return lodash.assingIn;
                }
                
                //return whatever you need to export for this module
                return {
                    assingIn:assingIn
                }
            }
        ]
);

Application entry point

"use strict";

let ambria = require('ambria');

// register lodash into Ambria
ambria.module('lodash', require('lodash'));

// just call require and this module will be registered into ambria 
// with all of his dependencies injected
require('./ressource/one.module')

Use

Ambria is based on a unique function "module". which return a loaded module. It can be used in four way.

Register a module which has some dependencies :

//we asume that dependencyOne and dependencyTwo has already been registered.
ambria
    .module('myModule', 
    [
        'dependencyOne', 'dependencyTwo', 
        function myModuleFunction(dependencyOne, dependencyTwo){...}
    ]);

Register a module with dependencies (auto binding) :

// dependencyOne and dependencyTwo will be found by their name 
// from already registered module list, and injected into myModule
ambria.module('myModule', [function myModuleFunction(dependencyOne, dependencyTwo){...}]);

Register a module which does not have any dependencies :

ambria.module('lodash', lodash)
//just don't wrap it into an Array, and Ambria will just register the module "has it"

Get an already registered module :

ambria.module('myModule')

Tips

To initialize Ambria with some module who don't need any injection, module function can be chain like it :

ambria
    .module('lodash', lodash)
    .module('express', express)
    .module('somethingElse', somethingElse)

In fact, ambria add its module function on every loaded module. If this module already has an attribute named module, ambria will return an object with a function named "get" to retrieve the loaded module and the Ambria module function.

Contributing

Contributions are welcome as long as you add test. Please send separate merge requests and don't combine things.

License

MIT - see LICENSE.md.