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

easyioc

v0.1.13

Published

Stupidly simple recursive IoC service provider.

Downloads

3,467

Readme

Easyioc.js

Stupidly simple Inversion of Control for node.js apps.

Belongs to the Encore framework project: encore.jit.su | github.com/rm-rf-etc/encore

NPM

Description

Easyioc is a container. You add modules to the container. Those modules receive their dependencies automatically from the container when exec() is invoked.

// simplified example

var ioc = require('easyioc')
var example = { foo:'bar' }

// Add the example object, but name it "models".
ioc
.add('models', example)
.add('app', app)
.exec()

function app(models){ // 'app' requires 'models'
    console.log(models)
    // prints: { foo: 'bar' }
}

Detects and explains circular dependencies: [Error: Dependency circle encountered: Mod_B ➤ Mod_C ➤ Mod_A ➤ Mod_B]

Alerts for missing dependencies: Error: Module "a" requires unknown dependency "thing".

Because you can specify any function as a dependency, you can easily adapt any existing modules (lodash, express, etc) to suit your use.

Use add() to include any of the following:

  • any function
  • any object
  • any valid string for require()
  • or any array of these

Usage

// moduleA.js
module.exports = function(){
    return 1+2
}
// moduleB.js
module.exports = function(){
    return 'A'+'B'
}
// main.js
module.exports = function(A, B){
    console.log(A, B)
}
// start.js
var ioc = require('easyioc')
ioc
.add( 'main', __dirname+'/main' )
.add( 'A', __dirname+'/moduleA' )
.add( 'B', __dirname+'/moduleB' )
.exec()

// use __dirname if require gets lost

The first argument (optional) is the name you are giving the module which all other modules will use to require it. Easyioc.add('redis') will add a module named 'redis' which equals require('redis').

Arrays are intended for adding many files which don't need to be required by other modules. However, if you provide a name, then the resulting module will be an array containing the objects and/or functions and/or require results from the array you provided.

Easyioc works really well with filefetcher (git) (npm). Together, they can automatically load your entire project, very simply, and according to your own specs.

Recursive Design

Easyioc also supports providing itself as a dependency, which allows subsequent modules to add even more modules and execute once more.

var easyioc = require('easyioc')

function app(ioc){

    function bestModuleEvar(_){
        console.log( _(process).has('exit') )
    }
    ioc
        .add( bestModuleEvar )
        .add( '_', 'lodash-node' )
        .exec()
}

easyioc
    .add(  app  )
    .add( 'ioc', easyioc  )
    .exec()

Sequential Loading

If you need to load data into a module before other modules are to run, you can invoke exec() to control the execution order.

// fileA.js
module.exports = function(models){
    models.modelA = {property: 'some data'}
    models.modelB = {property: 'some data'}
}
// fileB.js
module.exports = function(models){
    models.modelC = {property: 'some data'}
    models.modelD = {property: 'some data'}
}

So lets say we have these ^ files, and we need to have the data in these objects loaded so we can use them in other files.

var easyioc = require('easyioc')

easyioc
    .add( 'models', {} )
    .add( ['fileA', 'fileB'] )
    .exec()
    .add( 'controllers' )
    .exec()
// Assume our controllers make reference to the models we created above.

How To Run The Tests

$ git clone http://github.com/rm-rf-etc/easyioc.git
$ cd easyioc
$ npm install expect.js
$ npm install -g mocha
$ mocha

License

The MIT License (MIT)

Copyright (c) 2013 Rob Christian

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.