# anchorjs

> [![Build Status](https://travis-ci.org/cshum/anchorjs.svg?branch=master)](https://travis-ci.org/cshum/anchorjs)

Latest version **0.2.4** (published 2015-01-22) · MIT license · 0 weekly downloads

## Install

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

## 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.4 |
| Published | 2015-01-22 |
| First published | 2014-11-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 19 |
| Author | Adrian C Shum |
| Maintainers | cshum |
| Keywords | api, util, hooks, middleware |

## Links

- npm: https://www.npmjs.com/package/anchorjs
- Repository: git@github.com:cshum/anchorjs
- Homepage: https://github.com/cshum/anchorjs
- Issues: https://github.com/cshum/anchorjs/issues
- npm.io page: https://npm.io/package/anchorjs

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.2.4 (latest) — 2015-01-22
- 0.2.3 — 2014-12-25
- 0.2.2 — 2014-12-19
- 0.2.1 — 2014-12-03
- 0.2.0 — 2014-11-17
- 0.1.2 — 2014-11-07

## README

# AnchorJS

[![Build Status](https://travis-ci.org/cshum/anchorjs.svg?branch=master)](https://travis-ci.org/cshum/anchorjs)

AnchorJS is a (express inspired) middleware layer for scaffolding asynchronous JavaScript methods. 

## Installation

Node.js

```bash
$ npm install anchorjs
```

Browser

Include the Anchor.js browser build in your pages.

```html
<script src="anchor.js" type="text/javascript"></script>
```

This will provide `anchor` as a global object, or `define` it if you are using AMD.

##Example

Middleware

```js
var anchor = require('anchorjs');

function Clock(){
  this._tick = 'tick';
  this._tock = 'tock';
}
anchor(Clock.prototype)
  .use(function(ctx, next){
    ctx.logs = ['clock',this._tick];
    next();
  })
  .use('tock',function(ctx, next){
    ctx.logs.push(this._tock);
    next();
  })
  .define(['tick','tock'],function(ctx, done){
    ctx.logs.push('done');
    done(null, ctx.logs);
  });

var clock1 = new Clock();
var clock2 = new Clock();

//middleware on prototypal instance
clock2.use('tick',function(ctx, next){
  ctx.logs.push('tick2');
  next();
});
clock2.use('tock',function(ctx, next){
  next('booooom'); //error
});

//Results
clock1.tick(console.log.bind(console)); //null [ 'clock', 'tick', 'done' ]
clock1.tock(console.log.bind(console)); //null ['clock','tick','tock','done']
clock2.tick(console.log.bind(console)); //null ['clock','tick','tick2','done']
clock2.tock(console.log.bind(console)); //'booooom'
```
## Changelog

`0.2.4`
- ADD array support for middleware arguments

`0.2.3`
- ADD scope

`0.2.2`
- ADD onEnd callback

`0.2.1`
- Clean up unnecessary API methods

`0.2.0`
- ADD params parser middleware

`0.1.2`
- Simplify API

## License

MIT

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