# fn-buffer

> Buffer function calls till you flush

Latest version **0.2.3** (published 2022-01-02) · 0 weekly downloads

## Install

```sh
npm install fn-buffer
pnpm add fn-buffer
yarn add fn-buffer
bun add fn-buffer
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.3 |
| Published | 2022-01-02 |
| First published | 2021-12-27 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | laggingreflex |
| Keywords | buffer, function |

## Links

- npm: https://www.npmjs.com/package/fn-buffer
- Repository: https://github.com/laggingreflex/fn-buffer
- Homepage: https://github.com/laggingreflex/fn-buffer#readme
- Issues: https://github.com/laggingreflex/fn-buffer/issues
- npm.io page: https://npm.io/package/fn-buffer

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads
- [datasets-fi-postalcodes](https://npm.io/package/datasets-fi-postalcodes.md) — 1.1K weekly downloads

## Recent versions

- 0.2.3 (latest) — 2022-01-02
- 0.2.2 — 2022-01-02
- 0.2.1 — 2022-01-01
- 0.2.0 — 2022-01-01
- 0.1.0 — 2021-12-27

## README

# fn-buffer

Make your function buffer calls till you flush.

Useful to make [Backtrace logging](#backtrace-logging).

## Install

```sh
npm install fn-buffer
```

## API

```js
new BufferedFunction(fn, opts)
```

* **`fn`** `<function>(required)` The function to buffer calls of
* **`opts`** `[number|object]` Options or `capacity`
* **`opts.capacity`** `[number=10]` Capacity of the ring-buffer of the calls
* **`opts.flush`** `[number=capacity]` Auto-flush when buffer gets full
* **`opts.reverse`** `[boolean]` Reverse the order of buffer calls

## Example

```js
import BufferedFunction from 'fn-buffer'

const bufferedLog = new BufferedFunction(console.log);

bufferedLog('a')
bufferedLog('b')
bufferedLog('c')
bufferedLog('d')
bufferedLog('e')
/* Doesn't log anything yet */

bufferedLog.flush();
/* Logs everything at once */
```

### Backtrace logging

This can be used to create [backtrace-logging](http://www.exampler.com/writing/ring-buffer.pdf):

```js
import BufferedFunction from 'fn-buffer'

export const debug = new BufferedFunction(console.debug, { flush: 0 })
process.on('uncaughtExceptionMonitor', debug.flush)
```

This `debug` function will only log to console in the event of an `uncaughtException`.

See [**backtrace-logging**](https://github.com/laggingreflex/backtrace-logging) for a module that does exactly this.

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