Skip to content
Buy me a coffee

Installation

The package has no runtime dependencies and ships its own type definitions.

Terminal window
npm install @ylcnfrht/collections

The package ships ES module and CommonJS builds; the exports map picks the right one and its type definitions. Everything is a named export of the package root. There are no deep imports.

import { ArrayList } from '@ylcnfrht/collections';
const names = new ArrayList<string>();
names.add('Ada');
console.log(names.toString()); // → [Ada]
const { ArrayList } = require('@ylcnfrht/collections');

The package exports interfaces and factories named List, Set, Map and Iterator. Importing Set or Map shadows the JS built-in in that module, and the library’s Set and Map are not constructible. Alias them on import, or reach the built-ins through globalThis.

import { Map as CMap, HashMap } from '@ylcnfrht/collections';
const ours: CMap<string, number> = new HashMap<string, number>();
const native = new globalThis.Map<string, number>();
console.log(ours.size(), native.size); // → 0 0
  • The library is plain ES2020 with no Node-specific APIs. It runs in modern browsers, Deno, Bun, workers and edge runtimes.
  • Bundlers select the ESM build through the exports map. The package is a single module, so unused classes are tree-shaken only as far as the bundler can prove them unused. Importing the package registers the stream engine with the collections, which is why list.stream() works without importing Stream.
  • using s = list.stream() works only where the runtime defines Symbol.dispose.
  • A bundler or minifier may rename classes (HashMap2). Printing and equality are unaffected; only constructor.name and class names quoted in some error messages change. Exception names stay the same.
Runtime Support
Node.js 18 and newer
Browsers Evergreen browsers (ES2020)
TypeScript 5.x recommended