# huggybear

> On demand, persistent and unobstrusive dependencies

Latest version **0.2.0** (published 2013-07-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install huggybear
pnpm add huggybear
yarn add huggybear
bun add huggybear
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2013-07-08 |
| First published | 2013-05-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Xavier Cambar |
| Maintainers | xcambar |

## Links

- npm: https://www.npmjs.com/package/huggybear
- Repository: https://github.com/xcambar/huggybear
- Issues: https://github.com/xcambar/huggybear/issues
- npm.io page: https://npm.io/package/huggybear

## Dependencies (1)

- [es6-shim](https://npm.io/package/es6-shim.md) ~0.7.0

## Recent versions

- 0.2.0 (latest) — 2013-07-08
- 0.1.0 — 2013-05-13

## README

# Huggy Bear

![](./huggy.jpg)

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

## What it does

> TL;DR; Mixins without the mess

HuggyBear helps you add behaviour to your objects (typically model instances) without compromising their public signatures.

## Status

[![Codeship Status for xcambar/huggybear](https://www.codeship.io/projects/721a51e0-c901-0130-f9d1-72c77f53de0a/status?branch=master) ](https://www.codeship.io/projects/4795)
[![Coverage Status](https://coveralls.io/repos/xcambar/huggybear/badge.png)](https://coveralls.io/r/xcambar/huggybear)


## 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` that originally contains 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__ helps keeping your models sane and simple.

## Some code, please

````javascript
var huggyBear = require('huggybear')();

function People () {
  huggyBear.provide(this, 'EventEmitter', new EventEmitter());
}

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

var ppl = new People();
// The following will throw a TypeError, obviously
ppl.on('eventName', function () {});

//This is the HuggyBear way:
pplEventEmitter = huggyBear.claim(ppl, 'EventEmitter');
pplEventEmitter.on('eventName', function () {}); //OK
````

> Of course, this will work with any object
>
> You don't have to put it in the constructor, of course.
> You're free to add functionnality whenever you need to.

# Tips on using huggyBear

## HuggyBear everywhere

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

````javascript
var huggyBear = require('huggybear')();

Object.prototype.provide = function (name, definition) {
  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)));
}
````

## License

MIT

---
_Source: https://npm.io/package/huggybear · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
