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

@pujansrt/dsx-ts

v1.0.9

Published

Type-safe data-structure implementations in TypeScript.

Downloads

50

Readme

Typed Data Structure

npm version install size codecov

A TypeScript-first library that provides a production-ready collection of fundamental and advanced data structures implemented in modern TypeScript. The library prioritizes type safety, performance, and developer experience while maintaining minimal, readable code suitable for both educational and production use cases.


Features

  • Type-safe implementations in modern TypeScript
  • Core structures: Queue, Stack, LRU Cache, Priority Queue, Bloom Filter, BK-Tree
  • Advanced support coming: Trie, Skip List
  • Minimal, clean, readable codebase for learning and use
  • Full test coverage with Jest

Data Structures Included

| Structure | File | Description | |----------------|---------------------|------------------------------------------------------| | Queue | queue.ts | FIFO queue with optional capacity | | Stack | stack.ts | LIFO stack | | LRU Cache | lru-cache.ts | Least Recently Used cache with eviction | | TTL Cache | ttl-cache.ts | TTL cache with expiring value | | Priority Queue | priority-queue.ts | Min/Max heap-based priority queue | | Bloom Filter | bloom-filter.ts | Probabilistic structure for fast membership checking | | BK-Tree | bk-tree.ts | Approximate string matching with edit distance | | Aho Corasick | aho-corasick.ts | Aho Corasick string matching algorithm |


Quick Start

1. Install

npm install @pujansrt/dsx-ts

2. Import and Use

Example: Queue

A basic first-in-first-out structure ideal for buffering or scheduling tasks.

import { Queue } from "@pujansrt/dsx-ts";
const queue = new Queue<number>();
queue.enqueue(1);
queue.enqueue(2);
console.log(queue.dequeue()); // 1

Example: Priority Queue

Use a priority queue when elements need to be processed based on their priority (e.g., job scheduling, pathfinding like Dijkstra's algorithm)

const pq: PriorityQueue<number> = new PriorityQueue(); // min-heap by default
pq.add(30);
pq.add(10);
pq.add(70);
pq.add(50);

while(!pq.isEmpty()) {
    console.log("v=",pq.poll());
}

Example: LRU Cache

Useful for caching recently used items with automatic eviction of the least recently accessed entries.

const cache: LRUCache<string, number>  = new LRUCache(2);
cache.put('a', 10);
cache.put('b', 20);
console.log("Cache value = ",cache.get('a'));

Example: Auto Expiring Cache (TTL Cache)

A cache that automatically removes items after a specified time-to-live (TTL).

import { TTLCache } from "@pujansrt/dsx-ts";
const cache: TTLCache<string, number> = new TTLCache(1000); // 1 second TTL
cache.put('a', 10);
setTimeout(() => {
    console.log(cache.get('a')); // undefined, as it has expired
}, 1100);

Example: Bloom Filter

Best for fast approximate membership checks at large scale (e.g., checking whether an email has already been seen). Very space-efficient with controlled false positives.

const filter: BloomFilter  = new BloomFilter(100, [hashFnv1a, hashDjb2]);
const items = ['apple', 'banana', 'kiwi'];
items.forEach((i) => filter.add(i));
const falsePositive = filter.has('peach');
console.log(falsePositive);

Example: BK-Tree

Used for fuzzy matching and typo-tolerant search (e.g., spellcheck, autocorrect). Efficient for nearest-neighbor search based on edit distance.

import { BKTree } from "@pujansrt/dsx-ts";
const tree = new BKTree<string>(levenshtein);
['book', 'back', 'boon', 'cook', 'nook'].forEach((word) => tree.add(word));
const results = tree.search('book', 1);
console.log(results); // ['book', 'boon', 'cook']

Example: Aho Corasick String Matching

The Aho-Corasick algorithm is a powerful and efficient string-matching algorithm. If you have a fixed set of "keywords" (a dictionary) that you want to find in a potentially very long input string, Aho-Corasick is highly efficient.

import { AhoCorasick } from "@pujansrt/dsx-ts";
const ac = new AhoCorasick(['he', 'she', 'his', 'hers']);
const text = 'ushers';
const matches = ac.search(text);
console.log(matches);

Contributing

Feel free to fork and submit PRs to add more data structures or improve performance. Suggestions and feedback welcome!

License

MIT License — free for personal and commercial use.

👤 Author

Developed and maintained by Pujan Srivastava, a mathematician and software engineer with 18+ years of programming experience.