Skip to content

docs: complete documentation overhaul, UMD removal, and 10 new utility methods#405

Merged
avoidwork merged 55 commits intomasterfrom
tweaks2
Mar 29, 2026
Merged

docs: complete documentation overhaul, UMD removal, and 10 new utility methods#405
avoidwork merged 55 commits intomasterfrom
tweaks2

Conversation

@avoidwork
Copy link
Copy Markdown
Owner

@avoidwork avoidwork commented Mar 29, 2026

Summary

This PR introduces comprehensive documentation improvements, removes obsolete UMD builds, adds test coverage for utility methods, and introduces new utility methods (peek(), cleanup(), getMany(), hasAll(), hasAny(), expiresAt(), sizeByTTL(), keysByTTL(), valuesByTTL(), onEvict()) to the tiny-lru cache library.

Key Changes

Documentation Overhaul

  • README.md: Complete rewrite with clearer examples, improved structure, and accurate comparison table values (verified bundle sizes vs lru-cache and quick-lru)
  • API.md: Methods now sorted alphabetically with expanded table of contents (1-3 level headers)
  • AGENTS.md: Updated project structure, coverage metrics (100% lines, 99.25% branches, 100% functions), and build output documentation
  • TECHNICAL_DOCUMENTATION.md: Updated build configuration docs

Build System

  • UMD removed: Deleted dist/tiny-lru.umd.js, dist/tiny-lru.umd.min.js, and dist/tiny-lru.umd.min.js.map
  • Updated rollup.config.js to support only ESM and CommonJS formats
  • UMD is obsolete in 2026 - modern bundlers (Webpack, Rollup, Vite) all support ESM natively

Breaking changes

  • Renamed resetTtl parameter/property to resetTTL

New Methods

  • peek(key): Retrieve a value without updating LRU order or performing TTL checks
  • cleanup(): Remove expired items without affecting LRU order
  • getMany(keys): Batch retrieve multiple items
  • hasAll(keys): Batch existence check - returns true if ALL keys exist
  • hasAny(keys): Batch existence check - returns true if ANY key exists
  • expiresAt(key): Get expiration timestamp for a key
  • sizeByTTL(): Get counts of items by TTL status
  • keysByTTL(): Get keys filtered by TTL status
  • valuesByTTL(): Get values filtered by TTL status
  • onEvict(callback): Register callback for evicted items

Test Coverage

  • Added comprehensive tests for all 9 new utility methods
  • Added tests for noTTL items in sizeByTTL()/keysByTTL()
  • All 149 tests passing with 100% line coverage

Minor Fixes

  • Fixed incorrect resetTtl documentation (was "via get()", now "via set()")
  • Removed readonly from type definitions (matches actual implementation)
  • Fixed README badge URLs and removed duplicate tag line

Files Changed

File Changes
README.md Complete rewrite, corrected comparison table, added doc links
AGENTS.md Updated to reflect dist/ structure, coverage metrics
docs/API.md Alphabetical ordering, expanded ToC
docs/TECHNICAL_DOCUMENTATION.md Updated build docs
types/lru.d.ts Fixed resetTtl doc, removed readonly properties, added all new methods
src/lru.js Added peek(), cleanup(), getMany(), hasAll(), hasAny(), expiresAt(), sizeByTTL(), keysByTTL(), valuesByTTL(), onEvict()
tests/unit/lru.test.js Added comprehensive tests for all new utility methods
rollup.config.js Removed UMD output
.github/workflows/ci.yml Added master branch push events

- peek() retrieves value without moving item in LRU order
- peek() does not perform TTL checks or delete expired items
- All core operations remain O(1)
- Updated tests, documentation, and AGENTS.md
- Added 68 new tests covering forEach, getMany, hasAll, hasAny, cleanup, toJSON, stats, onEvict, sizeByTTL, keysByTTL, and valuesByTTL methods
- Refactored values() to directly iterate linked list instead of using keys()
- Refactored forEach() for direct linked list traversal
- Updated API documentation in docs/API.md
- Updated README.md method table
- Updated AGENTS.md API reference
- All tests passing (145/145)
- Added test for items with expiry=0 when ttl>0 (manual expiry set)
- Covers uncovered lines 534-535 and 563-564 in sizeByTTL and keysByTTL
- 100% line coverage achieved
- Compress badges to first 8 lines after title
- Add new badges: GitHub stars, Codecov
- Organize content with clear sections
- Add modern usage patterns (LLM caching, session auth)
- Improve 'Why Tiny LRU?' comparison table
- Add detailed API reference with all methods
- Include TypeScript examples
- Add security best practices
- Remove duplicate TypeScript section
- Standardize method descriptions
- Add comprehensive code examples

Fixes: branch name references (master vs main)
- Update bundle sizes to actual measured values (gzipped)
- Fix quick-lru TTL support (it does support maxAge)
- Replace inaccurate 'Comprehensive API' column with 'Pure LRU'
- Methods now sorted A-Z: cleanup() to valuesByTTL()
- Expanded table of contents with 1-3 level headers
- All method anchors now directly link to section headers
- Removed redundant TECHNICAL_DOCUMENTATION link in Security section
- Added Documentation section with links to all three docs files
- Corrected resetTtl doc to say 'via set()' instead of 'via get()'
- Removed 'readonly' from class properties (implementation doesn't use readonly)
@avoidwork avoidwork self-assigned this Mar 29, 2026
@avoidwork avoidwork changed the title docs: complete documentation overhaul, UMD removal, and new methods docs: complete documentation overhaul, UMD removal, and 10 new utility methods Mar 29, 2026
@augmentcode
Copy link
Copy Markdown

augmentcode bot commented Mar 29, 2026

🤖 Augment PR Summary

Summary: Expands tiny-lru’s public API with new utility/introspection methods, modernizes distribution outputs, and refreshes documentation/tests.

Changes:

  • Adds utilities: peek(), cleanup(), getMany(), hasAll(), hasAny(), TTL grouping helpers (sizeByTTL()/keysByTTL()/valuesByTTL()), stats(), and onEvict().
  • Introduces internal #stats and increments counters across get/set/delete/evict paths.
  • Updates values() to avoid calling keys() when no keys are provided, traversing the linked list directly.
  • Removes UMD bundles and updates Rollup config to emit ESM, minified ESM, and CommonJS only.
  • Overhauls README/API/technical docs and adds extensive unit tests for the new methods.
  • Adjusts CI workflow to also run on pushes to master.

Technical Notes: Type definitions were updated to include the new APIs and to type items[key] as possibly undefined (matching runtime behavior).

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 5 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

- When evicting items, ensure both prev and next pointers are cleared
- This prevents keeping the rest of the list reachable when consumers
  hold references to evicted nodes
- Items with expiry === 0 represent noTTL items, not expired items
- Changed cleanup() to only remove items where expiry !== 0 && expiry <= now
- This matches the semantics in sizeByTTL()/keysByTTL()
@avoidwork
Copy link
Copy Markdown
Owner Author

augment review

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

- Properly unlink expired nodes during cleanup() deletion
- Clear prev/next pointers to allow garbage collection
- Fix iteration to save next pointer before unlinking
…ined>

This correctly reflects that items[key] returns undefined for missing keys,
Prevents runtime error if onEvict() is called with undefined or non-function value.
The evict() method already checked #onEvict !== null, but that allows non-functions.
@avoidwork
Copy link
Copy Markdown
Owner Author

augment review

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 5 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

clear() now iterates through linked list to nullify prev/next pointers,
allowing proper garbage collection of nodes.
The sets counter increments in both set() and setWithEvicted() methods.
Updated documentation to reflect actual behavior.
The delete count includes both explicit delete() calls AND internal
removal of expired items by get(). Update the documentation to reflect
this behavior accurately.
Remove the redundant nodei.co npm badge which duplicated npm version
and downloads information already shown in the badges above.
- Properties: first, last, max, resetTtl, size, ttl
- Methods: clear, cleanup, delete, entries, evict, forEach, get, getMany,
  has, hasAll, hasAny, keys, keysByTTL, onEvict, peek, set, setWithEvicted,
  sizeByTTL, stats, toJSON, values, valuesByTTL, expiresAt
Updated Methods table to be alphabetically sorted:
- cleanup, clear, delete, entries, evict, expiresAt, forEach, get,
  getMany, has, hasAll, hasAny, keys, keysByTTL, onEvict, peek,
  set, setWithEvicted, sizeByTTL, stats, toJSON, values, valuesByTTL
@avoidwork
Copy link
Copy Markdown
Owner Author

augment review

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

- cleanup() returns number, not  (documented in Method Chaining section)
- setWithEvicted() TTL reset behavior on updates with resetTtl=true
- values() example comment: 'respects LRU order' -> 'order matches input array'
- onEvict() parameter validation throws TypeError
- forEach() thisArg type: Object -> *
- entries() return type: Array<[string, *]> -> Array<(string|*)[]>
- dist/tiny-lru.min.js is available in repo but not packaged for npm
- Only dist/tiny-lru.js, dist/tiny-lru.cjs, and types/lru.d.ts are shipped
- getMany() calls get() for each key
- Updates LRU order (items move to MRU position)
- Removes expired items (affects stats: hits, misses, deletes)
- Clarify this is not a read-only operation
@avoidwork
Copy link
Copy Markdown
Owner Author

augment review

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

@avoidwork avoidwork merged commit 938c79d into master Mar 29, 2026
4 checks passed
@avoidwork avoidwork deleted the tweaks2 branch March 29, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant