Skip to content

Repository files navigation

@avensio/shared

npm versionnpm downloadsDocumentationGitHubLicense

Documentation · GitHub

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.

Highlights

  • 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/graph with dedicated docs. This package focuses on the shared data-structure primitives that power other Avensio libraries.

Installation

pnpm add @avensio/shared
# npm install @avensio/shared# yarn add @avensio/shared

Usage (ESM/CommonJS)

import{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')

Browser via IIFE bundle

<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.

Comparator helpers

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/DESC and stringComparatorASC/DESC are built-in specializations.

Modules at a glance

ModuleWhat it contains
ListsList, LinkedList, DoublyLinkedList, CyclicLinkedList with functional helpers.
QueuesQueue, LinkedQueue, PriorityQueue, Dequeue for FIFO/LIFO hybrids.
StacksArray-based Stack + linked variant for constant-time operations.
HeapsBinary and Fibonacci heaps with printHeap for debugging tree structure.
SortingQuickSort + HeapSort implementations operating on ISortable collections.
MathPoint utility with x/y/z coordinates.
UtilitiesOrdering, 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.

Documentation

Every exported member is documented with accurate complexity data, examples, and cross-links:

Benchmarks & tests

  • Run the Vitest suite with coverage: pnpm test
  • Execute micro-benchmarks (lists/queues/stacks): pnpm bench — results per round are tracked in test/benchmarks/README.md
  • Development mode with watch/coverage logging: pnpm dev

Development & release workflow

CommandDescription
pnpm lintESLint with auto-fix over src/
pnpm buildBuilds ESM + IIFE bundles and regenerates types
pnpm docs:devLaunches VitePress (docs/) locally
pnpm cleanRemoves node_modules/ and dist/
pnpm releaseRuns tests + build + changelog (changelogen) before publishing

Package publishing is handled by the publish workflow.

See docs/development.md and CONTRIBUTING.md for contributor details.

Links

About

TypeScript data structures and algorithms for Node.js and browsers: lists, stacks, queues, heaps, binary search trees, comparators, sorting utilities, and points. Ships as typed ESM, CJS, and IIFE bundles.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages