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

buncha

v1.0.20

Published

An IoC container supports Annotation Scanner, Automatically Detect Code Changes and Hot Reload. Inspired by Spring Framework

Downloads

37

Readme

What is buncha?

  • IoC Container - Buncha is essential package to build a powerful, large application
  • Invoke Function and Construct Object - Find the correct arguments automatically to invoke functions or construct an object from class.
  • Dependency Manager - Manage dependencies of services in container. Auto detect dependency cycle.
  • Annotation Scanner - Buncha uses @Service annotation to detect services in projects.
  • Watch File Changes and Auto Reload - Hate restarting application to apply the changes every time modify a file? Buncha detects changes and reload it and all dependents for you automatically.
  • Fast Execution - Buncha usually spends less than 0.02 milliseconds to parse and start invoking a function or constructing an object. See benchmark test

Install

$ npm install --save buncha

Register services manually

//Declare services
var userService = function () {
    //...
}
var ReportService = function (userService) {
    //...
}
//Register services. The registration order is NOT important
var container = new (require("buncha").Container)();
container.registerByConstructor("reportService", ReportService);
container.register("userService", userService);

//Get service by name
var reportService = container.resolve("reportService");
var services = container.resolve(["reportService", "userService"])

Invoke function and construct object

function generateReport (userService, reportService) {
    //...
}

function Report (reportService, userService, type){
    //...
}

//Buncha finds correct arguments to invoke the function
var report1 = container.invoke(generateReport);

//Add missingResolver {type:"pdf"}
//Missingresolver can be a function(parameterName){}
var report2 = container.construct(Report, {type:"pdf"});

Using service annotation to declare a service

Create file service/order-service.js with annotation @Service in multi-line comment block

/**
 * @Service(name="orderService")
 *
 */
module.exports = OrderService;
function OrderService (userService, reportService) {
    //...
}

Scan and watch

Use buncha to scan all services in service directory

var container = new (require("buncha").Container)();
var promise = container.scan( ["service"] );// .scan("service") is also OK.

We can also use .watch() to scan and watch all changes of services to auto reload them:

var container = new (require("buncha").Container)();
var promise = container.watch(["service"]);

Default services in IoC container:

  • $construct
  • $invoke
  • $register
  • $registerByConstructor
  • $resolve
  • $resolveByAnnotation

Function utility

function hello(name, age){
    //...
}
var User = function(name, age){
    this.getName = function(){
        return name;
    }
    this.getAge = function(){
        return age;
    }
}
var user = new User("Tom", 10);

var Fx = require("buncha").Fx;
var parameters = Fx.extractParameters( hello ); //return ["name", "age"]
var methods = Fx.getMethodNames( user ); //return ["getName", "getAge"]
var annotations = Fx.extractAnnotations( fileContentInString ); //return all annotations

Benchmark

On my machine, Buncha usually spends only more 0.00122 ms to 0.009347 ms to parse and invoke a function and 0.001195 ms to 0.020473 ms to construct an object.

Following is the result of my test:

Benchmark result of $invoke:
Wo Container: It takes 34ms to invoke 1000000 times.
W/ Container, Wo Caching: It takes 9381ms to invoke 1000000 times. Average time spent by Buncha: 0.009347ms
W/ Container, With Caching: It takes 1254ms to invoke 1000000 times. Average time spent by Buncha: 0.00122ms

Benchmark result of $construct:
Wo Container: It takes 38ms to construct 1000000 times.
W/ Container, Wo Caching: It takes 20511ms to construct 1000000 times. Average time spent by Buncha: 0.020473ms
W/ Container, With Caching: It takes 1233ms to construct 1000000 times. Average time spent by Buncha: 0.001195ms

Run the benchmark test:

$ mocha --grep "Benchmark"

Author

Tho Q Luong thoqbk.github.io

License

MIT