
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
round-robin-js
Advanced tools
A JavaScript library that implements round-robin algorithms for managing items in a cyclic order. This library provides three types of round-robin implementations:
It also has TypeScript definitions for all classes.
npm install round-robin-js
// JS
const {
PriorityRoundRobin,
RandomRoundRobin,
SequentialRoundRobin
} = require('round-robin-js');
// TS
import {
PriorityRoundRobin,
RandomRoundRobin,
SequentialRoundRobin,
RoundRobinItem
} from 'round-robin-js';
All round-robin types share the following interface:
add(value): Adds a new item.
value
: The value to add.RoundRobinItem<T>
).deleteByKey(key): Deletes an item by its key.
key
: The key of the item to delete.true
if the item was deleted, false
otherwise.deleteByValue(callback): Deletes items that satisfy the given callback function.
callback
: A function that takes an item value and returns true
if the item should be deleted.next(): Retrieves the next item in the round-robin sequence.
RoundRobinItem<T>
) or null
if the queue is empty.count(): Returns the total number of items in the round-robin.
clear(): Clears all items from the round-robin.
reset(): Resets the round-robin to its initial state.
Processes items in the order they were added, cycling through sequentially.
new SequentialRoundRobin<T>(values?: T[])
values
: An optional array of initial values.const sequentialRR = new SequentialRoundRobin(['A', 'B', 'C']);
console.log(sequentialRR.next()); // { key: 0, value: 'A' }
console.log(sequentialRR.next()); // { key: 1, value: 'B' }
console.log(sequentialRR.next()); // { key: 2, value: 'C' }
console.log(sequentialRR.next()); // { key: 0, value: 'A' } // cycles back
Processes items in a random order. Each item is processed once per round before restarting.
new RandomRoundRobin<T>(values?: T[])
values
: An optional array of initial values.const randomRR = new RandomRoundRobin([1, 2, 3, 4]);
console.log(randomRR.next()); // A random item
console.log(randomRR.next()); // Another random item
Processes items based on priority, where the highest-priority item is processed first (depending on your compare function).
new PriorityRoundRobin<T>(
compare: (a: T, b: T) => number,
values?: T[]
)
compare
: A comparison function (a, b) => number
to determine priority of items.values
: An optional array of initial values.const priorityRR = new PriorityRoundRobin((a, b) => b - a, [5, 2, 8]);
priorityRR.add(10);
console.log(priorityRR.next()); // { key: 3, value: 10 }
Each item in the round-robin is represented as an object with the following shape:
interface RoundRobinItem<T> {
key: number; // A unique sequential key
value: T; // The original value
}
This library is licensed under the MIT License. See LICENSE for details.
[3.0.8] - 2025-Jan-26
FAQs
an implementation of round robin as a data structure
We found that round-robin-js demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.