# mediocre

> - pre-hooks - post-hooks -

Latest version **0.2.0** (published 2014-12-01) · BSD license · 0 weekly downloads

## Install

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

## 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 | 2014-12-01 |
| First published | 2013-10-19 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Maintainers | architectd |

## Links

- npm: https://www.npmjs.com/package/mediocre
- Repository: https://github.com/classdojo/mediocre.js
- Issues: https://github.com/classdojo/mediocre.js/issues
- npm.io page: https://npm.io/package/mediocre

## Dependencies (5)

- [sift](https://npm.io/package/sift.md) 0.0.16
- [async](https://npm.io/package/async.md) 0.7.x
- [protoclass](https://npm.io/package/protoclass.md) 0.0.x
- [type-component](https://npm.io/package/type-component.md) 0.0.1
- [bindable-object](https://npm.io/package/bindable-object.md) 0.0.x

## Recent versions

- 0.2.0 (latest) — 2014-12-01
- 0.1.0 — 2014-10-14
- 0.0.15 — 2014-08-08
- 0.0.14 — 2014-05-27
- 0.0.12 — 2014-05-27
- 0.0.11 — 2014-05-22
- 0.0.10 — 2014-05-22
- 0.0.9 — 2014-04-29
- 0.0.8 — 2014-01-24
- 0.0.6 — 2013-11-20
- 0.0.5 — 2013-11-18
- 0.0.3 — 2013-11-18
- 0.0.2 — 2013-11-14
- 0.0.1 — 2013-10-23
- 0.0.0 — 2013-10-19

## README

### Mediocre.js [![Alt ci](https://travis-ci.org/classdojo/mediocre.js.png)](https://travis-ci.org/classdojo/mediocre.js)

Mediocre is a lightweight JavaScript mediator.

### Features

- ability to add pre / post hooks
- ability to call commands with options (see below)

```javascript
var mediator = require("mediocre")();

mediator.on("validate", function (message, next) {
    for(var param in message.options) {
      //validate fields against message.data
    }
});

//login helper
mediator.on("login", function (message, next) {
  console.log(message.data);
});


//add pre-hook into login to validate fields
mediator.on("pre login", { validate: { username: "string", password: "string" }});


// spy on a message being executed
mediator.spy({ redirect: /.*?/ }, function (message, listeners) {
  message.once("success", function () {

  });
});

```


## API

### mediator.on(event, listeners...)

adds a listener

### mediator.execute(listener[, data][, callback])

executes a command

### message mediator.message(name[, data][, options])

creates a new message option to dispatch

```javascript
mediator.on("hello", function(message, options) {
  console.log(message.options.message); // world!
});

mediator.on("sayHelloWorld", { hello: { message: "world!" }});

//executes hello with options world
mediator.execute(mediator.message("hello", null, { message: "world!" }));

//same as above command
mediator.execute("sayHelloWorld");
```

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