ringway
v1.0.7
Published
A ring buffer implementation in JavaScript
Downloads
4
Readme
Usage
Initialize a ring-buffer with 5 slots:
import Ringway from 'ringway';
const ringbuffer = new Ringway(5);
API
- write - writes an element or an array of elements before overwriting and returns the number of elements written to the buffer
- read - returns a single buffered element in FIFO order, and removes it from the buffer
- getAll - get all buffer elements
- clear - clears buffer
- isEmpty - returns a boolean value indicating if the buffer is empty
- isFull - returns a boolean value indicating if the buffer is full
- maxSize - returns max size of the buffer
Config
- debug - if the property has true value, messages with additional information will be written in console
- schema - determines if data will be validated by provided schema with Joi API. Not valid elements won't be written in buffer
Example
const ringbuffer = new Ringway(5, {
debug: true,
schema: function() {
return this.Joi.number().integer();
}
});
ringbuffer.write([1, 2, 3]);
ringbuffer.read()