Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b8c9355
Add CLAUDE.md and AGENTS.md, replace eslint with oxfmt/oxlint
avoidwork Mar 20, 2026
6bf7ef8
Remove .cursor directory
avoidwork Mar 20, 2026
0d34942
Update AGENTS.md with project info, remove c8 dependency
avoidwork Mar 21, 2026
b4f1e2e
Remove mocha and c8 dependencies, simplify test script
avoidwork Mar 21, 2026
b0cba3a
Update oxfmt and oxlint versions
avoidwork Mar 21, 2026
2be6af3
Use Node's native test runner
avoidwork Mar 21, 2026
c92facc
Replace new Array() with Array.from() to fix lint warnings
avoidwork Mar 21, 2026
dee4f55
Audit fixes: has() TTL check, evict() null guard, lazy default params…
avoidwork Mar 21, 2026
c4bfb3c
Rewrite README.md for new and experienced developers
avoidwork Mar 21, 2026
4b03957
Add docs/API.md with complete API reference
avoidwork Mar 21, 2026
6d0ea31
Update CODE_STYLE_GUIDE.md with actual coding conventions
avoidwork Mar 21, 2026
645897f
Update TECHNICAL_DOCUMENTATION.md to reflect actual implementation
avoidwork Mar 21, 2026
c8d04ba
Revert TECHNICAL_DOCUMENTATION.md changes
avoidwork Mar 21, 2026
d125a12
Fix TECHNICAL_DOCUMENTATION.md to accurately reflect implementation
avoidwork Mar 21, 2026
87c71f0
Fix Mathematical Foundation section in TECHNICAL_DOCUMENTATION.md
avoidwork Mar 21, 2026
281b3f0
Fix memory leak, stale data, and improve performance
avoidwork Mar 21, 2026
5eac383
Update AGENTS.md with common issues and implementation notes
avoidwork Mar 21, 2026
26a6e14
Remove dead code in moveToEnd()
avoidwork Mar 21, 2026
9d4f7c1
Update lint script to check formatting
avoidwork Mar 21, 2026
f5fa3fe
Replace fmt script with fix script
avoidwork Mar 21, 2026
e96fca9
Apply formatting fixes
avoidwork Mar 21, 2026
87d89fe
Add coverage script and rename test file
avoidwork Mar 21, 2026
96736a2
Add tests for 100% line coverage
avoidwork Mar 21, 2026
1dad65b
Add test coverage info to README
avoidwork Mar 21, 2026
e5f5109
Remove unused eslint config
avoidwork Mar 21, 2026
f235aa9
Fix Mathematical Foundation section to match implementation
avoidwork Mar 21, 2026
b40d6b4
Update TypeScript definitions to match implementation
avoidwork Mar 21, 2026
458f414
Rebuild distribution files
avoidwork Mar 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .cursor/rules/javascript.mdc

This file was deleted.

77 changes: 77 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# AGENTS.md

## Project Overview

`tiny-lru` is a high-performance, lightweight LRU (Least Recently Used) cache library for JavaScript with O(1) operations and optional TTL support.

## Setup Commands

```bash
npm install # Install dependencies
npm run build # Lint and build (runs lint then rollup)
npm run rollup # Build with rollup
npm run test # Run lint and tests
npm run mocha # Run tests with coverage (c8)
npm run fmt # Format code with oxfmt
npm run lint # Lint code with oxlint
```

## Development Workflow

Source code is in `src/`.

- **lint**: Check and fix linting issues with oxlint
- **fmt**: Format code with oxfmt
- **build**: Lint + rollup build
- **mocha**: Run test suite with coverage reporting

## Project Structure

```
├── src/lru.js # Main LRU cache implementation
├── tests/ # Test files
├── benchmarks/ # Performance benchmarks
├── dist/ # Built distribution files
├── types/ # TypeScript definitions
├── docs/ # Documentation
├── rollup.config.js # Build configuration
└── package.json # Project configuration
```

## Code Style

- Indentation: Tabs
- Quotes: Double quotes
- Semicolons: Required
- Array constructor: Avoid `new Array()` (oxlint will warn)

## API Reference

- `lru(max, ttl, resetTtl)` - Factory function to create cache
- `LRU` class - Direct instantiation with `new LRU(max, ttl, resetTtl)`
- Key methods: `get()`, `set()`, `delete()`, `has()`, `clear()`, `evict()`
- Array methods: `keys()`, `values()`, `entries()`
- Properties: `first`, `last`, `max`, `size`, `ttl`, `resetTtl`

## Testing

- Framework: Node.js built-in test runner (`node --test`)
- Coverage: 100% (c8)
- Test pattern: `tests/**/*.js`
- All tests must pass with 100% coverage before merging
- Run: `npm test` (lint + tests)

## Common Issues to Avoid

- **Memory leaks**: When removing items from the linked list, always clear `prev`/`next` pointers to allow garbage collection
- **LRU order pollution**: Methods like `entries()` and `values()` should access items directly rather than calling `get()`, which moves items and can delete expired items mid-iteration
- **TTL edge cases**: Direct property access (`this.items[key]`) should be used instead of `has()` when you need to inspect expired-but-not-yet-deleted items
- **Dead code**: Always verify edge case code is actually reachable before adding special handling
- **Constructor assignment**: Use `let` not `const` for variables that may be reassigned (e.g., in `setWithEvicted`)

## Implementation Notes

- The LRU uses a doubly-linked list with `first` and `last` pointers for O(1) operations
- TTL is stored per-item as an `expiry` timestamp; `0` means no expiration
- `moveToEnd()` is the core method for maintaining LRU order - item is always moved to the `last` position
- `setWithEvicted()` optimizes updates by avoiding the full `set()` path for existing keys
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@AGENTS.md
Loading
Loading