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

@try.bivek/dsts

v1.0.1

Published

A lightweight TypeScript library providing essential data structures with full type support.

Readme

DSTS - Data Structures TypeScript

A lightweight TypeScript library providing essential data structures with full type support.

📦 Installation

npm i @try.bivek/dsts

🚀 Quick Start

import { LinkedList, Stack, Queue, MinHeap } from '@try.bivek/dsts';

// Create a typed linked list
const list = new LinkedList<number>();
list.insertAtHead(42);

// Create a typed stack
const stack = new Stack<string>();
stack.push("Hello World");

// Create a typed queue
const queue = new Queue<boolean>();
queue.enqueue(true);

// Create a min heap
const heap = new MinHeap();
heap.insert(10);

📚 Data Structures

LinkedList

A generic singly linked list implementation.

import { LinkedList } from '@try.bivek/dsts';

const list = new LinkedList<number>();

// Insert at head
list.insertAtHead(1);
list.insertAtHead(2); // List: 2 -> 1

// Insert at tail
list.insertAtTail(3); // List: 2 -> 1 -> 3

// Delete by value
list.deleteValue(1); // List: 2 -> 3

// Access head node
const head = list.head; // ListNode<number> | null
if (head) {
  console.log(head.value); // 2
  console.log(head.next?.value); // 3
}

Methods:

  • insertAtHead(value: T): void - Insert element at the beginning
  • insertAtTail(value: T): void - Insert element at the end
  • deleteValue(value: T): void - Delete first occurrence of value

Properties:

  • head: ListNode<T> | null - Reference to the first node

Stack

A generic LIFO (Last In, First Out) stack implementation.

import { Stack } from '@try.bivek/dsts';

const stack = new Stack<string>();

// Push elements
stack.push("first");
stack.push("second");
stack.push("third");

// Peek at top element
console.log(stack.peek()); // "third"

// Pop elements
console.log(stack.pop()); // "third"
console.log(stack.pop()); // "second"

// Check if empty
console.log(stack.isEmpty()); // false
console.log(stack.pop()); // "first"
console.log(stack.isEmpty()); // true

Methods:

  • push(value: T): void - Add element to top
  • pop(): T | undefined - Remove and return top element
  • peek(): T | undefined - Return top element without removing
  • isEmpty(): boolean - Check if stack is empty

Queue

A generic FIFO (First In, First Out) queue implementation.

import { Queue } from '@try.bivek/dsts';

const queue = new Queue<number>();

// Enqueue elements
queue.enqueue(1);
queue.enqueue(2);
queue.enqueue(3);

// Peek at front element
console.log(queue.peek()); // 1

// Dequeue elements
console.log(queue.dequeue()); // 1
console.log(queue.dequeue()); // 2

// Check if empty
console.log(queue.isEmpty()); // false
console.log(queue.dequeue()); // 3
console.log(queue.isEmpty()); // true

Methods:

  • enqueue(value: T): void - Add element to rear
  • dequeue(): T | undefined - Remove and return front element
  • peek(): T | undefined - Return front element without removing
  • isEmpty(): boolean - Check if queue is empty

MinHeap

A min heap implementation for numbers (smallest element at root).

import { MinHeap } from '@try.bivek/dsts';

const heap = new MinHeap();

// Insert elements
heap.insert(10);
heap.insert(5);
heap.insert(15);
heap.insert(3);

// Access internal array (for debugging)
console.log(heap.heap); // [3, 5, 15, 10]

// Extract minimum
console.log(heap.extractMin()); // 3
console.log(heap.extractMin()); // 5
console.log(heap.extractMin()); // 10
console.log(heap.extractMin()); // 15
console.log(heap.extractMin()); // undefined (empty heap)

Methods:

  • insert(val: number): void - Insert a number into the heap
  • extractMin(): number | undefined - Remove and return the minimum element

Properties:

  • heap: number[] - Internal array representation of the heap

🎯 Usage Examples

Building a Task Priority System

import { MinHeap, Queue } from '@try.bivek/dsts';

interface Task {
  id: string;
  priority: number;
  description: string;
}

class TaskManager {
  private priorities = new MinHeap();
  private taskQueue = new Queue<Task>();

  addTask(task: Task) {
    this.priorities.insert(task.priority);
    this.taskQueue.enqueue(task);
  }

  getNextTaskPriority(): number | undefined {
    return this.priorities.extractMin();
  }

  processNextTask(): Task | undefined {
    return this.taskQueue.dequeue();
  }
}

Implementing Undo Functionality

import { Stack } from '@try.bivek/dsts';

interface Action {
  type: string;
  data: any;
  timestamp: Date;
}

class UndoRedoManager {
  private undoStack = new Stack<Action>();
  private redoStack = new Stack<Action>();

  executeAction(action: Action) {
    this.undoStack.push(action);
    // Clear redo stack when new action is performed
    while (!this.redoStack.isEmpty()) {
      this.redoStack.pop();
    }
  }

  undo(): Action | undefined {
    const action = this.undoStack.pop();
    if (action) {
      this.redoStack.push(action);
    }
    return action;
  }

  redo(): Action | undefined {
    const action = this.redoStack.pop();
    if (action) {
      this.undoStack.push(action);
    }
    return action;
  }
}

🔧 TypeScript Support

This package is written in TypeScript and provides full type definitions. All generic data structures (LinkedList<T>, Stack<T>, Queue<T>) support any type:

// String stack
const stringStack = new Stack<string>();

// Object queue
interface User {
  id: number;
  name: string;
}
const userQueue = new Queue<User>();

// Custom type linked list
type Product = {
  id: string;
  price: number;
};
const productList = new LinkedList<Product>();

📝 API Reference

ListNode

class ListNode<T> {
  value: T;
  next: ListNode<T> | null;
  constructor(value: T);
}

Time Complexities

| Data Structure | Operation | Time Complexity | |---------------|-----------|-----------------| | LinkedList | insertAtHead | O(1) | | LinkedList | insertAtTail | O(n) | | LinkedList | deleteValue | O(n) | | Stack | push | O(1) | | Stack | pop | O(1) | | Stack | peek | O(1) | | Queue | enqueue | O(1) | | Queue | dequeue | O(1) | | Queue | peek | O(1) | | MinHeap | insert | O(log n) | | MinHeap | extractMin | O(log n) |

🤝 Contributing

This package is open for contributions. Feel free to submit issues and pull requests.

📄 License

MIT License

🔗 Links


Happy coding! 🚀