Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
circular_buffer_js
Advanced tools
Fast TS/JS implementation of a circular buffer (aka ring queue, cyclic list, etc.) Extremely well tested.
npm install --save-dev circular_buffer_js
Typescript
implementation of a circular buffer, and JS compiles to a es6
module minified, es6 commonjs minified, es6 iife minified, and es6 iife full.
es6
minified module build is currently 1.4k.typescript
are involved.You should consider viewing the real documentation, but:
// yields a buffer of fixed size `size`
const cb = new circular_buffer(size),
cb2 = circular_buffer.from([1,2,3]);
cb.push(item); // inserts `item` at end of `cb`, then returns `item`
cb.shove(item); // inserts `item` at end of `cb`; remove if needed, returns removed
cb.pop(); // removes and returns first element
cb.at(location); // shows the element at 0-indexed offset `location`
cb.pos(location); // shows the element at run-indexed offset `location`
cb.offset(); // shows the delta from 0-indexed to head
cb.indexOf(item); // returns the index of the first `item`, or -1
cb.find(pred); // return the the first match or undefined
cb.every(pred); // tests if every queue element satisfies the predicate
cb.some(pred); // tests if at least one element satisfies the predicate
cb.fill(item); // maxes `length` and sets every element to `item`
cb.clear(); // empties the container
cb.reverse(); // reverses the container
cb.resize(size,pE); // change to new size, truncating if required; pE to prefer end
cb.toArray(); // return an array of the current contents of the queue
cb.first; // returns the first value in the queue; throws when empty
cb.last; // returns the last value in the queue; throws when empty
cb.isFull; // returns `true` if no space left; `false` otherwise
cb.isEmpty; // returns `true` if no space remains; `false` otherwise
cb.available; // returns the number of spaces remaining currently
cb.capacity; // returns the total `size` allocated
cb.length; // returns the amount of space currently used
This is a circular buffer (or cycle buffer, ring queue, etc.) It was written because a library I wanted to use had a native buggy implementation, so I provided something more trustworthy.
A circular buffer is a fixed size buffer that allows you to push and pop forever, as a first in first out queue-like structure. Circular buffers are more efficient than queues, but can overflow.
import { circular_buffer } from 'circular_buffer_js';
const cb = new circular_buffer(3); // [ , , ]
cb.push(1); // ok: [1, , ]
cb.push(2); // ok: [1,2, ]
cb.push(3); // ok: [1,2,3]
cb.at(0); // 1
cb.first; // 1
cb.last; // 3
cb.push(4); // throws - full! ; [1,2,3]
cb.pop(); // 1: [2,3, ]
cb.at(0); // 2: [2,3, ]
cb.push(4); // ok: [2,3,4]
cb.push(5); // throws - full! ; [2,3,4]
cb.pop(); // 2: [3,4, ]
cb.pop(); // 3: [4, , ]
cb.pop(); // 4: [ , , ]
cb.pop(); // throws - empty! ; [ , , ]
It's typescript, so you can also
import { circular_buffer } from 'circular_buffer_js';
const cb = new circular_buffer<number>(3);
And there's a CommonJS build, so you can
const cbuf = require('circular_buffer_js'),
circular_buffer = new cbuf.circular_buffer;
There're also two iife
builds - both regular and minified - so that you can
use this in older browsers, or from CDN.
<script defer type="text/javascript" src="circular_buffer_js.min.js"></script>
<script defer type="text/javascript">
window.onload = () => {
console.log(
`Using circular buffer version ${circular_buffer.version}`
);
// package // class
const mybuf = new circular_buffer.circular_buffer(5);
};
</script>
If this doesn't meet your needs, please try:
FAQs
Fast TS/JS implementation of a circular buffer (aka ring queue, cyclic list, etc.) Extremely well tested.
We found that circular_buffer_js 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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.