npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

js-collections-utils

v0.0.1

Published

JavaScript utility collections equivalent to java.utils - includes LinkedList, PriorityQueue, and related data structures

Readme

This is js-util equivalent of java.utils

LinkedList Methods

  • iterator(): Returns an iterator over the elements in this collection.
  • toArray(): Returns an array containing all of the elements in this collection.
  • addAll(collection): Adds all of the elements in the specified collection to this collection.
  • removeAll(collection): Removes all of this collection's elements that are also contained in the specified collection.
  • retainAll(collection): Retains only the elements in this collection that are contained in the specified collection.
  • containsAll(collection): Returns true if this collection contains all of the elements in the specified collection.
  • subList(fromIndex, toIndex): Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
  • add(element): Appends the specified element to the end of the list.
  • addAtIndex(index, element): Inserts the specified element at the specified position in the list.
  • removeAtIndex(index): Removes the element at the specified position in the list.
  • remove(element): Removes the first occurrence of the specified element from this list.
  • get(index): Returns the element at the specified position in the list.
  • set(index, element): Replaces the element at the specified position in the list with the specified element.
  • size(): Returns the number of elements in the list.
  • clear(): Removes all elements from the list.
  • isEmpty(): Returns true if the list contains no elements.
  • contains(element): Returns true if the list contains the specified element.
  • sort(comparator): Sorts this list using the supplied comparator function.
  • indexOf(element): Returns the index of the first occurrence of the specified element.
  • lastIndexOf(element): Returns the index of the last occurrence of the specified element.

Deque Methods

  • addFirst(element): Inserts the specified element at the front of this deque.
  • addLast(element): Inserts the specified element at the end of this deque.
  • removeFirst(): Retrieves and removes the first element of this deque.
  • removeLast(): Retrieves and removes the last element of this deque.
  • getFirst(): Retrieves, but does not remove, the first element of this deque.
  • getLast(): Retrieves, but does not remove, the last element of this deque.
  • peekFirst(): Retrieves, but does not remove, the first element of this deque, or returns null if empty.
  • peekLast(): Retrieves, but does not remove, the last element of this deque, or returns null if empty.
  • offerFirst(element): Inserts the specified element at the front (returns false if capacity-restricted).
  • offerLast(element): Inserts the specified element at the end (returns false if capacity-restricted).
  • pollFirst(): Retrieves and removes the first element, or returns null if empty.
  • pollLast(): Retrieves and removes the last element, or returns null if empty.
  • push(element): Pushes an element onto the stack (equivalent to addFirst).
  • pop(): Pops an element from the stack (equivalent to removeFirst).

Queue Methods

  • offer(element): Inserts the specified element into this queue (returns false if capacity-restricted).
  • poll(): Retrieves and removes the head of this queue, or returns null if empty.
  • peek(): Retrieves, but does not remove, the head of this queue, or returns null if empty.
  • element(): Retrieves, but does not remove, the head of this queue (throws if empty).

PriorityQueue Methods

  • add(element): Inserts the specified element into the priority queue.
  • offer(element): Inserts the specified element into the priority queue (returns false if full).
  • remove(element): Removes a single instance of the specified element.
  • poll(): Retrieves and removes the head of the queue, or returns null if the queue is empty.
  • peek(): Retrieves, but does not remove, the head of the queue, or returns null if the queue is empty.
  • element(): Retrieves, but does not remove, the head of the queue (throws if empty).
  • size(): Returns the number of elements in the queue.
  • clear(): Removes all elements from the queue.
  • isEmpty(): Returns true if the queue contains no elements.
  • contains(element): Returns true if the queue contains the specified element.
  • toArray(): Returns a sorted array of all elements.
  • removeIf(filter): Removes all elements that satisfy the given predicate.
  • addAll(collection): Adds all elements from another collection.

Sample Code

LinkedList Example

let linkedList = new LinkedList<string>();
linkedList.add('A');
linkedList.add('B');
linkedList.addAtIndex(1, 'C');
console.log(linkedList.get(1)); // Output: C
linkedList.set(1, 'D');
console.log(linkedList.get(1)); // Output: D
console.log(linkedList.size()); // Output: 3
linkedList.removeAtIndex(1);
console.log(linkedList.contains('D')); // Output: false
linkedList.clear();
console.log(linkedList.isEmpty()); // Output: true

PriorityQueue Example

let priorityQueue = new PriorityQueue<string>();
priorityQueue.add('A');
priorityQueue.offer('B');
console.log(priorityQueue.peek()); // Output: A
console.log(priorityQueue.size()); // Output: 2
console.log(priorityQueue.poll()); // Output: A
console.log(priorityQueue.contains('B')); // Output: true
priorityQueue.clear();
console.log(priorityQueue.isEmpty()); // Output: true

LinkedList as Queue Example

let queue = new LinkedList<string>();
queue.offer('A');
queue.offer('B');
console.log(queue.peek()); // Output: A
console.log(queue.size()); // Output: 2
console.log(queue.poll()); // Output: A
console.log(queue.isEmpty()); // Output: false

Stack Example

let stack = new LinkedList<string>();
stack.push('A');
stack.push('B');
console.log(stack.peekFirst()); // Output: B
console.log(stack.size()); // Output: 2
console.log(stack.pop()); // Output: B
console.log(stack.isEmpty()); // Output: false

Deque Example

let deque = new LinkedList<string>();
deque.addFirst('A');
deque.addLast('B');
console.log(deque.peekFirst()); // Output: A
console.log(deque.peekLast()); // Output: B
console.log(deque.size()); // Output: 2
console.log(deque.removeFirst()); // Output: A
console.log(deque.isEmpty()); // Output: false

LinkedList Iterator Example

let linkedList = new LinkedList<string>();
linkedList.add('A');
linkedList.add('B');
linkedList.add('C');

let iterator = linkedList.iterator();
while (iterator.hasNext()) {
  console.log(iterator.next());
}
// Output: A B C

For-of Loop Example

let linkedList = new LinkedList<string>();
linkedList.add('A');
linkedList.add('B');
linkedList.add('C');

for (const item of linkedList) {
  console.log(item);
}
// Output: A B C