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

ts-ds

v1.0.32

Published

Data structure and algorithm in TypeScript

Downloads

188

Readme

ts-ds 📚

A powerful, convenient and lightweight library of data structures and algorithms in TypeScript.

🎯 Description

This library provides optimized implementations of popular data structures and algorithms that every developer needs. Written in TypeScript with full type support.

📦 Installation

npm install ts-ds

🚀 Usage

import { sort } from 'ts-ds';

const array = [64, 34, 25, 12, 22, 11, 90];
sort.selection(array);
console.log(array); // [11, 12, 22, 25, 34, 64, 90]

📋 Implementation Checklist

🔹 Fundamental Data Structures

Stack

  • [ ] push(value)
  • [ ] pop()
  • [ ] peek()
  • [ ] isEmpty()
  • [ ] size()
  • [ ] clear()

Queue

  • [ ] enqueue(value)
  • [ ] dequeue()
  • [ ] front()
  • [ ] isEmpty()
  • [ ] size()
  • [ ] clear()

LinkedList

  • [ ] add(value) / append(value)
  • [ ] insertAt(index, value)
  • [ ] removeAt(index)
  • [ ] remove(value)
  • [ ] get(index)
  • [ ] indexOf(value)
  • [ ] contains(value)
  • [ ] size()
  • [ ] clear()
  • [ ] toArray()

DoublyLinkedList

  • [ ] add(value)
  • [ ] insertAt(index, value)
  • [ ] remove(value)
  • [ ] get(index)
  • [ ] reverse()

📊 Hash-based and Set Structures

HashMap / Dictionary

  • [ ] set(key, value)
  • [ ] get(key)
  • [ ] has(key) / containsKey(key)
  • [ ] delete(key)
  • [ ] keys()
  • [ ] values()
  • [ ] entries()
  • [ ] size()
  • [ ] clear()

HashSet

  • [ ] add(value)
  • [ ] has(value)
  • [ ] delete(value)
  • [ ] size()
  • [ ] clear()
  • [ ] toArray()
  • [ ] union(otherSet)
  • [ ] intersection(otherSet)
  • [ ] difference(otherSet)

⚙️ Heap and Priority Structures

Heap (Min/Max)

  • [ ] push(value) / insert(value)
  • [ ] pop() / extractMin/Max()
  • [ ] peek()
  • [ ] size()
  • [ ] isEmpty()
  • [ ] heapify()

🌳 Tree Data Structures

Binary Search Tree (BST)

  • [ ] insert(value)
  • [ ] delete(value)
  • [ ] search(value) / contains(value)
  • [ ] inOrder()
  • [ ] preOrder()
  • [ ] postOrder()
  • [ ] findMin()
  • [ ] findMax()
  • [ ] height()
  • [ ] isBalanced()

AVL Tree

  • [ ] insert(value)
  • [ ] delete(value)
  • [ ] search(value)
  • [ ] getBalance(node)

Trie

  • [ ] insert(word)
  • [ ] search(word)
  • [ ] startsWith(prefix)
  • [ ] delete(word)
  • [ ] getAllWords()

🕸️ Graph Structures

Graph (Undirected & Directed)

  • [ ] addVertex(value)
  • [ ] addEdge(from, to, weight?)
  • [ ] removeVertex(value)
  • [ ] removeEdge(from, to)
  • [ ] getVertices()
  • [ ] getNeighbors(vertex)
  • [ ] hasVertex(value)
  • [ ] hasEdge(from, to)

Graph Algorithms

  • [ ] bfs(start)
  • [ ] dfs(start)
  • [ ] dijkstra(start)
  • [ ] bellmanFord(start)
  • [ ] floydWarshall()
  • [ ] topologicalSort()
  • [ ] kruskal()
  • [ ] prim()

🔀 Sorting and Searching Algorithms

Selection Sort

  • [x] selectionSort(arr, compareFn?)
  • [x] selectionSort tests
  • arr: array to sort in place.
  • compareFn: optional comparator returning negative, zero, or positive.
  • returns: void.
  • sort.selection(array) is an alias for selectionSort(array).
  • Selection sort finds the smallest element and swaps it to the beginning.

Bubble Sort

  • [x] bubbleSort(arr, compareFn?)
  • [x] bubbleSort optimized
  • arr: array to sort in place.
  • compareFn: optional comparator.
  • returns: void.
  • Bubble sort compares adjacent elements and swaps them until the array is sorted.
  • The implementation stops early when no swaps occur on a pass.

Insertion Sort

  • [x] insertionSort(arr, compareFn?)
  • arr: array to sort in place.
  • compareFn: optional comparator.
  • returns: void.
  • Insertion sort builds a sorted prefix by moving each element into its correct position.

Merge Sort

  • [x] mergeSort(arr, compareFn?)
  • arr: array to sort.
  • compareFn: optional comparator.
  • returns: new sorted array.
  • Merge sort divides the array, sorts both halves recursively, then merges them.

Quick Sort

  • [x] quickSort(arr, compareFn?)
  • arr: array to sort in place.
  • compareFn: optional comparator.
  • returns: sorted array (same reference).
  • Quick sort partitions by pivot and recursively sorts subarrays.

Heap Sort

  • [x] heapSort(arr, compareFn?)
  • arr: array to sort in place.
  • compareFn: optional comparator.
  • returns: void.
  • Heap sort uses a binary heap structure and repeatedly extracts the top element.

Counting Sort

  • [x] countingSort(arr)
  • arr: array of numbers.
  • returns: sorted number array.
  • Counting sort counts value frequencies and rebuilds the result from counts.
  • This implementation supports negative values.

Radix Sort

  • [x] radixSort(arr)
  • arr: array of integers.
  • returns: sorted number array.
  • Radix sort sorts by digit positions, processing least significant digits first.
  • The implementation handles negative numbers by sorting negatives separately.

Shell Sort

  • [x] shellSort(arr, compareFn?)
  • arr: array to sort in place.
  • compareFn: optional comparator.
  • returns: void.
  • Shell sort improves insertion sort by sorting elements at a gap distance.

Searching Algorithms

  • [ ] linearSearch(arr, value)
  • [ ] binarySearch(arr, value)
  • [ ] interpolationSearch(arr, value)
  • [ ] exponentialSearch(arr, value)

📄 License

MIT

👤 Author

Andrei Pliukhaev


👨‍💻 For Developers

Setup

  1. Clone the repository
  2. Install dependencies: npm install
  3. Make sure TypeScript is installed

Scripts

# Build project
npm run build

# Run tests
npm run test

# Watch for changes
npm run watch

# Format code
npm run format

Project Structure

src/
├── index.ts          # Main entry point
├── index.test.ts     # Main tests
└── sort/
    ├── selection/
    │   ├── selection.ts
    │   ├── selection.test.ts
    │   └── README.md
    └── data.ts

Development Guidelines

  • Follow TypeScript best practices
  • Write tests for all new features
  • Use Prettier for code formatting
  • Maintain comprehensive documentation
  • Keep data structures generic using TypeScript generics

Contributing

Feel free to submit issues and enhancement requests!