# @nichoth/utils

> Trying things

Latest version **0.0.2** (published 2017-05-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install @nichoth/utils
pnpm add @nichoth/utils
yarn add @nichoth/utils
bun add @nichoth/utils
```

## 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.0.2 |
| Published | 2017-05-20 |
| First published | 2017-05-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | nichoth |
| Maintainers | nichoth |

## Links

- npm: https://www.npmjs.com/package/@nichoth/utils
- Repository: https://github.com/nichoth/utils
- Homepage: https://github.com/nichoth/utils#readme
- Issues: https://github.com/nichoth/utils/issues
- npm.io page: https://npm.io/package/@nichoth/utils

## Dependencies (1)

- [nanobus](https://npm.io/package/nanobus.md) ^3.2.1

## Recent versions

- 0.0.2 (latest) — 2017-05-20
- 0.0.1 — 2017-05-20
- 0.0.0 — 2017-05-20

## README

# utils


## request.js

Broadcast async events to multiple subscribers

```js
var Request = require('../request')

function asyncCall (data, cb) {
    process.nextTick(function () {
        // echo
        cb(null, data)
    })
}

var req = Request('foo', asyncCall)

// Emit these events -- 'start', the key you passed in (or 'error'),
// and 'resolve'
// Also there is '*', which calls the subscriber with the event name
// and the response
// After the function calls back, all the listeners are removed
req({ myArgs: 'test' })
    .on('start', console.log.bind(console, 'start'))
    .on('foo', console.log.bind(console, 'foo'))
    .on('resolve', console.log.bind(console, 'resolve'))
    .on('error', console.log.bind(console, 'error'))
    .on('*', console.log.bind(console, 'log all events'))

/*
start { op: 'foo', args: { myArgs: 'test' } }
log all events start { op: 'foo', args: { myArgs: 'test' } }
resolve { op: 'foo', args: { myArgs: 'test' } }
log all events resolve { op: 'foo', args: { myArgs: 'test' } }
foo { myArgs: 'test' }
log all events foo { myArgs: 'test' }
*/

// if `myModel` has a key equal to the event name, call it
var myModel = MyModel()
Request('foo', asyncCall)({ myArgs: 'test' })
    .applyTo(myModel)
    .applyTo(myModel.request)

function MyModel () {
    return {
        foo: console.log.bind(console, 'foo'),
        request: {
            start: console.log.bind(console, 'start'),
            resolve: console.log.bind(console, 'resolve')
        }
    }
}
```

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