An open API service indexing awesome lists of open source software.

https://github.com/deployable/node-deployable-ringbuffer

RingBuffer - Store a limited data set in a circular array
https://github.com/deployable/node-deployable-ringbuffer

deployable nodejs npm-module ring-buffer

Last synced: 3 months ago
JSON representation

RingBuffer - Store a limited data set in a circular array

Awesome Lists containing this project

README

        

# [Deployable ringbuffer](https://github.com/deployable/node-deployable-ringbuffer)

Circular buffer stored in an array

### Install

npm install @deployable/ringbuffer --save

yarn add @deployable/ringbuffer

### Usage

```javascript

const RingBuffer = require('@deployable/ringbuffer')
const rb = new RingBuffer(5)

// Add items
rb.add('one')
rb.add('two')
rb.add('three')
rb.add('four')
rb.add('five')

// Get the last item
rb.last() // => 'five'

// Get the entire array
rb.toArray() // => [ 'one', 'two', 'three', 'four', 'five' ]

// Oldest on the left will be overwritten
rb.add('six')
rb.toArray() // => [ 'two', 'three', 'four', 'five', 'six' ]

// Clear the buffer down
rb.clear()
rb.toArray() // => [ , , , , ]

```

### License

deployable-ringbuffer is released under the MIT license.
Copyright 2016 Matt Hoyle Deployable Ltd

https://github.com/deployable/node-deployable-ringbuffer