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
- Host: GitHub
- URL: https://github.com/deployable/node-deployable-ringbuffer
- Owner: deployable
- License: mit
- Created: 2017-01-18T04:35:32.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-11T14:34:14.000Z (about 8 years ago)
- Last Synced: 2025-03-26T18:11:21.499Z (3 months ago)
- Topics: deployable, nodejs, npm-module, ring-buffer
- Language: JavaScript
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 --saveyarn 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 Ltdhttps://github.com/deployable/node-deployable-ringbuffer