# mthb-circular-buffer

> Circular buffer / ring buffer with overflow support

Latest version **0.0.45** (published 2019-10-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install mthb-circular-buffer
pnpm add mthb-circular-buffer
yarn add mthb-circular-buffer
bun add mthb-circular-buffer
```

## 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.45 |
| Published | 2019-10-29 |
| First published | 2019-09-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Magni Þór Birgisson |
| Maintainers | magni.thor |
| Keywords | CircularBuffer, RingBuffer, TypeScript, Overflow |

## Links

- npm: https://www.npmjs.com/package/mthb-circular-buffer
- Repository: https://github.com/Magnithor/CircularBuffer
- Homepage: https://github.com/Magnithor/CircularBuffer/blob/master/README.md
- Issues: https://github.com/Magnithor/CircularBuffer/issues
- npm.io page: https://npm.io/package/mthb-circular-buffer

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.45 (latest) — 2019-10-29
- 0.0.44 — 2019-10-29
- 0.0.43 — 2019-09-24
- 0.0.42 — 2019-09-23
- 0.0.4 — 2019-09-23
- 0.0.3 — 2019-09-23
- 0.0.2 — 2019-09-19
- 0.0.1 — 2019-09-19

## README

# CircularBuffer

[![GitHub issues](https://img.shields.io/github/issues/Magnithor/CircularBuffer)](https://github.com/Magnithor/CircularBuffer/issues)
![github languages](https://img.shields.io/github/languages/top/grant-zietsman/validate-typescript.png)

```javascript
import { CircularBuffer } from 'mthb-circular-buffer';
```

## Allow OverFlow = true
```javascript
var circularBuffer = new CircularBuffer(2 /*length*/, true /*allowOverFlow*/);
circularBuffer.push(1);
circularBuffer.push(2);
console.log(circularBuffer.size()); // 2
circularBuffer.push(3);
console.log(circularBuffer.size()); // 2
console.log(circularBuffer.pop());  // 2
console.log(circularBuffer.pop());  // 3
console.log(circularBuffer.size()); // 0
```

## Allow OverFlow = false
```javascript
var circularBuffer = new CircularBuffer(2 /*length*/, false /*allowOverFlow*/);
circularBuffer.push(1);
circularBuffer.push(2);
console.log(circularBuffer.pop()); // 1
console.log(circularBuffer.pop()); // 2
circularBuffer.push(3);
circularBuffer.push(4);
circularBuffer.push(5); // throw "overflow"
```

## Description and Big O 

Function | Big O | Description
---------|-------|------------
push | O(1)| push item to circular buffer
pop | O(1) | pop item of circular buffer
size | O(1) | size of circular buffer
export | O(n) | pop all items of circular buffer
clear | O(n) | clear all items of circular buffer

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