Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
circular-buffer
Advanced tools
This is a simple circular buffer implementation for NodeJS.
Below is a sample session with a circular buffer with this package. It should answer most questions.
var CircularBuffer = require("circular-buffer");
var buf = new CircularBuffer(3);
console.log(buf.capacity()); // -> 3
buf.enq(1);
buf.enq(2);
console.log(buf.size()); // -> 2
buf.enq(3);
buf.enq(4);
console.log(buf.size()); // -> 3 (despite having added a fourth item!)
buf.get(0); // -> 4 (last added item is at start of buffer)
buf.get(0,2); // -> [4,3,2] (2-parameter get takes start and end)
buf.toarray(); // -> [4,3,2] (equivalent to buf.get(0,buf.size() - 1) )
console.log(buf.deq()); // -> 4
buf.toarray(); // -> [3,2]
buf.deq(); // -> 3
buf.deq(); // -> 2
buf.toarray(); // -> []
buf.deq(); // -> throws RangeError("CircularBuffer dequeue on empty buffer")
size()
-> integer
capacity()
-> integer
enq(value)
value
at the start of the bufferdeq()
-> value
RangeError
when the buffer is empty on invocation.get(idx)
-> value
idx
. 0
is the start of the buffer (last-enqueued item), buf.size()-1
is the oldest item in the buffer.get(start,end)
-> [value]
start
up to and including index end
; returns an array. The newest item is first in the array, and it is the same as buf.get(start)
.toarray()
-> [value]
buf.get(0,buf.size() - 1)
: exports all items in the buffer in order.FAQs
A NodeJS simple circular buffer implementation supporting indexing
The npm package circular-buffer receives a total of 3,157 weekly downloads. As such, circular-buffer popularity was classified as popular.
We found that circular-buffer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.