TypeScript data-structure toolkit with lists, queues, stacks, heaps, sorting helpers, math utilities, and reusable comparator factories. Works in ESM, CommonJS, and browser environments (IIFE bundle) with zero runtime dependencies.
- Array-backed and linked lists (including cyclic/doubly variants) with map/filter/reduce helpers
- Queue family (FIFO, linked, priority, dequeue) plus stack implementations
- Binary and Fibonacci heaps with helper functions like
printHeap - Sorting utilities (quick sort, heap sort) and math primitives such as
Point - Flexible comparator factory (
createComparator) and ready-made number/string comparators
Looking for the graph implementation? It now lives in
@avensio/graphwith dedicated docs. This package focuses on the shared data-structure primitives that power other Avensio libraries.
pnpm add @avensio/shared
# npm install @avensio/shared# yarn add @avensio/sharedimport{List,Queue,createComparator,numberComparatorASC}from'@avensio/shared'constnumbers=newList([5,2,9])numbers.comparator=numberComparatorASCnumbers.sort()constqueue=newQueue<string>()queue.add('task-1')queue.add('task-2')console.log(queue.remove())// task-1constbyLength=createComparator<{title: string}>(item=>item.title.length,'desc')<scriptsrc="https://unpkg.com/@avensio/shared"></script><script>conststack=newStack()stack.push('first')stack.push('second')console.log(stack.pop())// second</script>The package ships dist/shared.es.js (ESM), dist/shared.cjs (CJS), and dist/shared.iife.js (browser) bundles plus dist/shared.es.d.ts for type information.
import{createComparator,numberComparatorDESC,stringComparatorASC}from'@avensio/shared'constbyScore=createComparator<{score: number}>('score')// asc by defaultconstbyTitleDesc=createComparator(item=>item.title,'desc')createComparator(keyOrExtractor, direction?)accepts either a property key or extractor function and returns a comparator compatible with every structure in this package.numberComparatorASC/DESCandstringComparatorASC/DESCare built-in specializations.
| Module | What it contains |
|---|---|
| Lists | List, LinkedList, DoublyLinkedList, CyclicLinkedList with functional helpers. |
| Queues | Queue, LinkedQueue, PriorityQueue, Dequeue for FIFO/LIFO hybrids. |
| Stacks | Array-based Stack + linked variant for constant-time operations. |
| Heaps | Binary and Fibonacci heaps with printHeap for debugging tree structure. |
| Sorting | QuickSort + HeapSort implementations operating on ISortable collections. |
| Math | Point utility with x/y/z coordinates. |
| Utilities | Ordering, ICollection, createComparator, and helper types such as Node<T>. |
Each module has detailed usage notes inside the docs/ folder (served via VitePress).
For a high-level comparison across structures, see docs/data-structures.md.
Every exported member is documented with accurate complexity data, examples, and cross-links:
- Run the Vitest suite with coverage:
pnpm test - Execute micro-benchmarks (lists/queues/stacks):
pnpm bench— results per round are tracked intest/benchmarks/README.md - Development mode with watch/coverage logging:
pnpm dev
| Command | Description |
|---|---|
pnpm lint | ESLint with auto-fix over src/ |
pnpm build | Builds ESM + IIFE bundles and regenerates types |
pnpm docs:dev | Launches VitePress (docs/) locally |
pnpm clean | Removes node_modules/ and dist/ |
pnpm release | Runs tests + build + changelog (changelogen) before publishing |
Package publishing is handled by the publish workflow.
See docs/development.md and CONTRIBUTING.md for contributor details.