ringway

1.0.7 • Public • Published

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()

Readme

Keywords

none

Package Sidebar

Install

npm i ringway

Weekly Downloads

3

Version

1.0.7

License

ISC

Unpacked Size

114 kB

Total Files

8

Last publish

Collaborators

  • ivankhludov