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

bilbo

v1.0.0

Published

Dependency Injection for JavaScript

Downloads

6

Readme

bilbo Build Status

Bilbo is a simple dependency injection library for JavaScript. It's intended audience is for node-js applications, but it can also be used for client-side applications.

He uses bags to store and distribute dependencies along your code. Bags are identifies by it's name within bilbo.

var bilbo = require("bilbo");
var bag = bilbo.bag("bag's name");

If there is no bag with a given name, bilbo.bag() will create one.

Fetching things from a bag is done by the bag.grab() method. Each thing is identified by it's name within the bag.

var thing = bag.grab("thing's name");

Bags can store things in many ways:

  • stuff: simple storage, no action performed
  • prototype: stores a prototype object used to create new objects having this one as prototype
  • factory: stores a function to be used as factory each time
  • lazy: stores a function that initializes an returns something that may be returned every time
  • type: stores a constructor function that may be used for creating new instances each time
  • singleton: stores a constructor function that may be used for create a single instance

stuff

Just stores something within the bag itself. No modification whatsoever is taken upon the stored data.

var myStuff = {};
 // stores myStuff under "stuff's name"
bag.stuff("stuff's name", myStuff);

// grabs back myStuff using "stuff's name"
var myStuffBack = bag.grab("stuff's name");

myStuff === myStuffBack; // true

prototype

Stores a prototype object. This object will be used as prototype for a newly created object each time bag.grab() is called.

var myPrototype = { a: {} };
// stores myPrototype under "prototype's name"
bag.prototype("prototype's name", myPrototype);

// grabs a new object having myPrototype as prototype using "prototype's name"
var myObject = bag.grab("prototype's name");

myObject.a === myPrototype.a; // true
myObject.hasOwnProperty("a"); // false

factory

Stores a factory function. This function will be used to create new things each time bag.grab() is called.

var myFactory = function() { return {}; };
// stores myFactory under "factory's name"
bag.factory("factory's name", myFactory);

// grabs oneThing created by the myFactory function
var oneThing = bag.grab("factory's name");
// grabs anotherThing created by the myFactory function
var anotherThing = bag.grab("factory's name");

oneThing === anotherThing; // false

lazy

Stores a lazy function. This function will be used only once to create a new thing when bag.grab() is called. Subsequent calls will return the same thing created the first time it was called.

var myLazy = function() { return {}; };
// stores myLazy under "lazy's name"
bag.lazy("lazy's name", myLazy);

// grabs a thing created by the myLazy function
var thing = bag.grab("lazy's name");
// grabs the sameThing created by the myLazy function previously
var sameThing = bag.grab("lazy's name");

thing === sameThing; // true

type

Stores a type constructor function. This function will be used as a constructor to create new type instances each time bag.grab() is called.

var MyConstructor = function() {};
// stores MyConstructor under "type's name"
bag.type("type's name", MyConstructor);

// grabs anInstance created by the MyConstructor function
var anInstance = bag.grab("type's name");
// grabs anotherInstance created by the MyConstructor function
var anotherInstance = bag.grab("type's name");

anInstance === anotherInstance; // false
anInstance instanceof MyConstructor; // true
anotherInstance instanceof MyConstructor; // true

singleton

Stores a type constructor function as a singleton. This function will be used as a singleton constructor to create a singleton instance once bag.grab() is called. Subsequent calls yields the same singleton instance.

var MySingletonConstructor = function() {};
// stores MySingletonConstructor under "singleton's name"
bag.singleton("singleton's name", MySingletonConstructor);

// grabs aSingleton created by the MySingletonConstructor function
var aSingleton = bag.grab("singleton's name");
// grabs sameSingleton created by the MySingletonConstructor function previously
var sameSingleton = bag.grab("singleton's name");

aSingleton === sameSingleton; // true
aSingleton instanceof MySingletonConstructor; // true