A simple Least Recently Used (LRU) cache implementation in TypeScript. Version 1.0.0 wraps sindresorhus/quick-lru with TypeScript declarations. It uses a Map internally for O(1) operations and supports keys of any type, including objects and symbols. Key features include configurable maxSize and maxAge (with per-item TTL), an onEviction callback for cleanup, and multiple iteration methods (keys, values, entriesAscending, entriesDescending). Compared to lru-cache or tiny-lru, quick-lru-ts focuses on simplicity and minimal API surface. The package is ESM-only, requires Node.js >=12, and is stable with no breaking changes expected. It is actively maintained as a TypeScript conversion of the original quick-lru.
npm install quick-lru-tsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates an LRU cache with max size 100 and default TTL 60 seconds. Sets two items, the second with a custom 30-second TTL. Demonstrates has, get, delete, and size.
Switch to import { QuickLRU } from 'quick-lru-ts' or use dynamic import().Use import { QuickLRU } from 'quick-lru-ts' instead of import QuickLRU from 'quick-lru-ts'.Either rely on onEviction callback or call get()/has() periodically to purge expired entries. No automatic eviction.
If you need async cleanup, queue the work (e.g., queueMicrotask) inside onEviction.
Always provide a positive integer for maxSize. Validation is not performed internally.
If you need TypeScript declarations, you can also use @types/quick-lru with the original package. Compare features before choosing.
Use import { QuickLRU } from 'quick-lru-ts' and ensure your project is configured for ESM (type: module in package.json or .mjs extension).If using import QuickLRU from 'quick-lru-ts', ensure the package version supports default export (v0.x). For v1.0.0, use named import: import { QuickLRU } from 'quick-lru-ts'.Ensure maxSize is a positive integer: new QuickLRU({ maxSize: Number(someValue) || 100 }).No dependency data recorded yet.