
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
circle-buffer
Advanced tools
A simple circular array buffer (also known as a ring buffer) for efficient management of string data in JavaScript/TypeScript.
This simple module is designed to manage a fixed-size buffer efficiently, with the ability to overwrite old data with new data as it arrives. This is useful in scenarios where memory usage needs to be constant and predictable, such as in real-time data processing, streaming applications, or when handling continuous data streams like logs, sensor data, or network packets.
npm install circle-buffer --save
import { CircularBuffer } from 'circle-buffer';
// Create a circular buffer with a limit of 5
const buffer = new CircularBuffer({ limit: 5 });
// Add values to the buffer
buffer.forward('A');
buffer.forward('B');
buffer.forward('C');
buffer.forward('D');
buffer.forward('E');
// Get the current state of the buffer
buffer.current(); // Output: 'ABCDE'
// Rewind the buffer
buffer.rewind();
// Get the updated buffer state
buffer.current(); // Output: 'ABCD'
// Get the buffer value at the specified position using index
buffer.get(1); // Output: 'B'
// Get the buffer value at the specified range using index and length
buffer.range(0,2); // Output: 'AB'
// Reset the buffer
buffer.reset();
// Get the buffer state after reset
buffer.current(); // Output: ''
CircularBuffernew CircularBuffer(options: { limit: number }): CircularBuffer
Creates a new instance of the CircularBuffer class with the specified limit.
options.limit: The maximum number of elements the circular buffer can hold.current(): string
Returns the current state of the buffer.
get(index: number): string
Returns the content at the specific position in the buffer.
index: The index position in the buffer.range(start: number, length: number): string
Returns the content at the specific range in the buffer.
start: The starting position in the buffer.length: The length of the range to fetch.reset(): void
Resets the buffer by filling it with empty strings.
forward(value: string): void
Moves the buffer forward by one position, adding the provided value at the end of the buffer. If the buffer is full, the oldest value is removed.
value: The string value to be added to the buffer.rewind(): void
Moves the buffer backward by one position, removing the last value. If the buffer becomes empty, an empty string is added at the beginning.
Suitable for various use cases involving the management of circular buffers that exclusively store strings or characters. Some potential use cases include:
Input History in a Console or Terminal:
Text Animation:
Textual Undo/Redo Functionality:
Rotating Text Displays:
Logging Recent Events:
String History in Interactive Applications:
String-based Sliding Windows:
Fixed-Size String Buffer in Resource-Constrained Environments:
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
A simple circular array buffer
The npm package circle-buffer receives a total of 5 weekly downloads. As such, circle-buffer popularity was classified as not popular.
We found that circle-buffer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.