# highoutput-utilities

> ## `delay(duration)` * `duration` `(number|string)` Amount of time to wait * Returns: `(Promise)`

Latest version **0.0.10** (published 2018-11-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install highoutput-utilities
pnpm add highoutput-utilities
yarn add highoutput-utilities
bun add highoutput-utilities
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.10 |
| Published | 2018-11-16 |
| First published | 2018-04-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 9.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | High Output Ventures |
| Maintainers | highoutput |

## Links

- npm: https://www.npmjs.com/package/highoutput-utilities
- npm.io page: https://npm.io/package/highoutput-utilities

## Dependencies (4)

- [ms](https://npm.io/package/ms.md) ^2.1.1
- [debug](https://npm.io/package/debug.md) ^3.1.0
- [limiter](https://npm.io/package/limiter.md) ^1.1.3
- [random-int](https://npm.io/package/random-int.md) ^1.0.0

## Recent versions

- 0.0.10 (latest) — 2018-11-16
- 0.0.9 — 2018-10-22
- 0.0.8 — 2018-10-22
- 0.0.7 — 2018-09-18
- 0.0.6 — 2018-08-10
- 0.0.4 — 2018-04-30
- 0.0.3 — 2018-04-25
- 0.0.2 — 2018-04-23
- 0.0.1 — 2018-04-23

## README

# Utilities

## `delay(duration)`
* `duration` `(number|string)` Amount of time to wait
* Returns: `(Promise)`

Wait for a given amount of time. The input can be a string compatible to the [`ms`](https://www.npmjs.com/package/ms) module.

### Examples
```javascript
import { delay } from 'highoutput-utilities';

async function main() {
  await delay(1000); // wait for 1 second

  await delay('1m'); // wait for 1 minute
}

main();
```

## `hash(message[,algorithm][,salt])`
* `message` `(string|Buffer)` Input message
* `algorithm` `(string)` Algorithm
* `salt` `(string|Buffer)`
* Returns: `(Promise<Buffer>)`

Generate hash.

### Examples
```javascript
import { hash } from 'highoutput-utilities';

hash('The quick brown fox jumps over the lazy dog.');
hash('The quick brown fox jumps over the lazy dog.', 'md5');
hash('The quick brown fox jumps over the lazy dog.', 'md5', 'secretsalt');
```

## `hmac(message[,key][,algorithm])`
* `message` `(string|Buffer)` Input message
* `key` `(string|Buffer)`
* `algorithm` `(string)` Algorithm
* Returns: `(Promise<Buffer>)`

Generate hash.

### Examples
```javascript
import { hmac } from 'highoutput-utilities';

hash('The quick brown fox jumps over the lazy dog.', 'secretkey');
hash('The quick brown fox jumps over the lazy dog.', 'secretkey', 'sha256');
```

## `rateLimiter(params)`
* `params` `(Object)`
  * `tokensPerInterval` `(Number)` Number of tokens to drip into the bucket over the course of one interval.
  * `interval` `(String|Number)` The interval length in milliseconds, or as one of the following strings: `second`, `minute`, `hour`, `day`.
  * `maxRetry` `(Number)` Number of tries before it will be considered as a fail.
  * `minInterval` `(Number)` Number of the minimum interval for retry delay.
* Returns: `(Promise<Function>)`
  * `consumeToken` `(Number)` Number of token to consume.
  * `cb` `(Function)` Function to be called when there is enough token to consume.
    * `err` `(Object)` Error object when there is an error occured.
    * `remainingRequests` Number of remaining token to be consumed right this moment.

```javascript
  import { RateLimiter } from 'highoutput-utilities';

  const limiter = RateLimiter({
    tokensPerInterval: 10,
    interval: 'second',
    maxRetry: 10,
    minInterval: 100,
  });

  async function process() {
    await limiter(5, () => {
      // your code goes here
    });
  }
  
  process();
```

### `rateLimiter.consume`

## Class: `Logger`
Generate logs that follow a certain format.

### `new Logger(tags)`
* `tags` `(Array<string>)`

### `logger.tag(tag)`-
* `tag` `(string)`
* Returns: `(Logger)`

### `logger.error(arg0[,arg1][,arg2]...)`
* `arg0` `(string|Object|)`
* `arg1` `(string|Object|)`
* `arg2` `(string|Object|)`

### `logger.warn(arg0[,arg1][,arg2]...)`
* `arg0` `(string|Object|)`
* `arg1` `(string|Object|)`
* `arg2` `(string|Object|)`

### `logger.info(arg0[,arg1][,arg2]...)`
* `arg0` `(string|Object|)`
* `arg1` `(string|Object|)`
* `arg2` `(string|Object|)`

### `logger.verbose(arg0[,arg1][,arg2]...)`
* `arg0` `(string|Object|)`
* `arg1` `(string|Object|)`
* `arg2` `(string|Object|)`

### `logger.silly(arg0[,arg1][,arg2]...)`
* `arg0` `(string|Object|)`
* `arg1` `(string|Object|)`
* `arg2` `(string|Object|)`

### Examples
```javascript
import { Logger } from 'highoutput-utilities';

const logger = new Logger(['api']);

logger.info('Read this!');
logger.error(new Error('A nasty error.'));
logger.silly('My dog will not bite you, probably.');
logger.verbose('You want some log?');
logger.warn('I kill you!');

logger.tag('http').verbose({ host: '127.0.0.1', pathname: '/' });
```

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