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

huggybear

v0.2.0

Published

On demand, persistent and unobstrusive dependencies

Downloads

5

Readme

Huggy Bear

Huggy was so cool he owned an iPad in the 70s!

What it does

HuggyBear does "silent mixin". It creates and stores functionnality for any object without never ever needing to compromise their structure or properties.

An example

Suppose an instance of the People prototype, with 3 methods: walk, sleep, work (very limited, huh?).

Now you want the instances of People to be also instances of EventEmitter, you'll have to add on, off, emit.

And now, you want the instances of People to do PubSub, then you add publish and subscribe.

So what ?

So your handcrafted People prototype, with the pure and beautiful simplicity of its 3 methods, has just lost its essence and is now a kind of a hydra with 8 methods, namely walk, sleep, work, on, off, emit, publish, register.

HuggyBear will keep your models sane and simple.

Some code, please

var huggyBear = require('huggybear');

function People () {
  huggyBear.provide(this, '/path/to/mixins/EventEmitter' /*, mixinArg1, mixinArg2 */);
}

People.prototype = {
  walk: function () {},
  sleep: function () {},
  work: function () {}
}

var ppl = new People();
ppl.on('eventName', function () {}); // throws TypeError, obviously
pplEventEmitter = huggyBear.claim('/path/to/mixins/EventEmitter');
pplEventEmitter.on('eventName', function () {}); //OK

You don't have to use the prototypal inheritance for HuggyBear to work. It's just that I'm kind of old fashioned, in some way.

You don't even have to put it in the constructor, of course. Add functionnality whenever you need to.

Building a mixin

To build a mixin, you must build a CommonJS module which exports MUST be a function. it can take any number of parameters, you will pass them by appending parameters to huggyBear#provide.

In other words, the exports of your module is the generator (aka the factory) of your mixin.

An exemple for a mixin of EventEmitter

var EventEmitter = require('events').EventEmitter;

module.exports = function () {
  return new EventEmitter();
};

For every object that wants this mixin to be provided, an instance of Emitter is created. Each object get its own instance.

Simple.

HuggyBear everywhere

You may want to bring HuggyBear to every object...

var huggyBear = require('huggybear');

Object.prototype.provide = function (/*name, arg1, arg2 */) {
  return huggyBear.provide.apply(undefined, [this].concat(Array.prototype.slice.call(arguments)));
}

Object.prototype.claim = function (/*name*/) {
  return huggyBear.claim.apply(undefined, [this].concat(Array.prototype.slice.call(arguments)));
}

Inception

You can use HuggyBear from HuggyBear to create multiple dependency containers, each being isolated from the other.

Testing

The tests and coverage reports are available in the TESTING file.

License

MIT