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

foldloader

v0.0.3

Published

Dependency manager, autoload and ioc container for your next NodeJs application

Readme

FoldLoader 🚀

Dependency manager, autoload and IoC container for Node.js

NPM Version Build Status Coveralls

Features

  1. Support for binding dependencies with unique namespaces.
  2. Autoloading multiple directories under a namespace.
  3. Defining aliases for bindings.
  4. Automatic resolution of namespaces and transparent dependency injection.
  5. Support for fakes when writing tests.
  6. Support for service providers, to bind dependencies in structured way.

Installation

You can install the package from npm.

npm i --save foldloader

Setup

using require

Require in main run

require('flodloader')

Config in file package.json

{
  "autoload": {
    "root": "App",
    "directories": {
      "app": "./src",
      "test": "./test"
    },
    "preLoadFiles": [
      "./start.js"
    ],
    "autoloads": {
      "App": "./src",
      "Test": "./test"
    }
  }
}
  • root : namespace Root of app
  • directories : defind folder using
const closure = ioc.use(resolver.forDir('app').translate(closure))
  • preLoadFiles : files load after run config autoload
  • autoloads : defind namespace of folder

Basic Usage

  • When require('flodloader') in main file, it will register two function globle is use and make

function use

 use(<namespace>)
  • file in node_modules
  • or file in namespace defind in autoloads with structure namespace + file || namespace + folder + file

function make

  • require file, constructor and inject to class
class Foo {
  static get inject () {
    return ['App/Bar']
  }

  constructor (bar) {
    this.bar = bar
  }
}

 const fooInstance = Ioc.make(Foo)

Namespace default Autoload

  const { ioc, resolver, registrar } = use('Autoload')
Using ioc
  • method bind bind file with file or object
class Foo {
}

ioc.bind('App/Foo', function () {
  return new Foo()
})
class Foo {
}

ioc.bind('App/Foo', function () {
  return Foo()
})
  • method singleton file with file or object as bind but is design pattern singleton
  • method alias create sholt name
ioc.alias('Model/Foo', 'Foo')
  • method use and make

  • method fake and singletonFake reqlace namespace have exits

  Ioc.fake('Adonis/Src/Lucid', function () {
    return FakeModel
  })
  • method restore namespace register
Ioc.restore('Adonis/Src/Lucid')
Ioc.restore('Adonis/Src/Lucid', 'Adonis/Src/Config')
Ioc.restore() // restore all
Using resolver
  • method forDir get directories was config in package.json
const closure = ioc.use(resolver.forDir('app').translate(closure))
  • method translate Translate binding using resolver translate
const closure = ioc.use(resolver.forDir('app').translate(closure))
  • method resolveResolves the binding from the IoC container. This method is a combination of translate and Ioc.make function.
  // class  App/User
 const handler = resolver.resolveFunc('App/User')
  • method resolveFunc Resolves a function by translating the binding and then validating the existence of the method on the binding object. Also if the binding param is a function, it will be recognized and returned.
  // with `find` as method of  App/User
 const handlerInstance = resolver.resolveFunc('App/User.find')
Using registrar
  • register provider class extendes to
  • all method register will call after all method boot
const { ServiceProvider } = require('flodloader')

class WsProvider extends ServiceProvider {
  register () {
    // this app as ioc
    this.app.singleton('Adonis/Addons/Ws', (app) => {
      const Ws = require('../src/Ws')
      const Config = app.use('Adonis/Src/Config')
      const Context = app.use('Adonis/Addons/WsContext')
      const Server = app.use('Adonis/Src/Server')
      return new Ws(Config, Context, Server)
    })
  }

  boot () {

  }
}
  • Have register Provider
// add provider
const { registrar } = use('Autoload')
registrar.providers(arrayProvider)
reiretrar.register()

Base

with structure folder

App
  | index.js
  | Model
    | User.js
  | Helpers
    | index.js
start.js
index.js
package.json
  • we have require Model/User.js anywhere
  const foo = ioc.use('Model/User')

Using bind

const { ioc } = use('Autoload')

class Foo {
}

ioc.bind('App/Foo', function () {
  return new Foo()
})

const foo = ioc.use('App/Foo')
// return Foo class instance

Simple enough! But we do not see the real power of the Ioc container, since we can instantiate the class manually too. Right? NO

Here are the following benefits.

  1. The author of the Foo class can decide how to instantiate the class and return a properly configured instance, instead of leaving it to the consumer.

  2. While you are making use of the Ioc container, one binding can be dependent upon others, without much work. For example


class Foo {
  constructor (config) {
    //
  }
}

ioc.bind('App/Foo', function (app) {
  const config = app.use('App/Config')
  return new Foo(config)
})

const foo = ioc.use('App/Foo')

Tests

Tests are written using japa. Run the following commands to run tests.

npm run test:local

# report coverage
npm run test

# on windows
npm run test:win

Extends

adonis-fold – @adonis-fold[email protected]