Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 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
38bd623
fix: rename cache variables in factory function example to avoid rede…
avoidwork Mar 29, 2026
81a7045
fix: correct values() example comment to reflect input key order
avoidwork Mar 29, 2026
282bd7e
feat: add oxlint.json configuration
avoidwork Mar 29, 2026
e9727f7
feat: add .oxfmtrc.json configuration
avoidwork Mar 29, 2026
341e6db
feat: update pre-commit hook to run fix, coverage, and stage all changes
avoidwork Mar 29, 2026
406a3d3
build: update dist files
avoidwork Mar 29, 2026
c988ca2
fix: clarify entries() and values() ordering in JSDoc
avoidwork Mar 29, 2026
543d6d1
build: update dist files
avoidwork Mar 29, 2026
4435b76
docs: add development principles (DRY, YAGNI, SOLID, OWASP)
avoidwork Mar 29, 2026
085e4f3
refactor: extract unlink() to eliminate linked list duplication
avoidwork Mar 29, 2026
9330ff4
build: update dist files
avoidwork Mar 29, 2026
5d9ed36
refactor: remove bypass parameter from set() to simplify API
avoidwork Mar 29, 2026
ab6843b
refactor: simplify set() and setWithEvicted() API by removing resetTt…
avoidwork Mar 29, 2026
8e85031
build: update dist files
avoidwork Mar 29, 2026
fa96113
docs: sort methods and properties alphabetically in README
avoidwork Mar 29, 2026
016ef16
docs: add badges, TypeScript example, comparison, and contributing guide
avoidwork Mar 29, 2026
748ad76
docs: update copyright year to 2026
avoidwork Mar 29, 2026
bad9e0e
docs: fix build badge URL to point to ci.yml
avoidwork Mar 29, 2026
5b47ce4
docs: restore coverage badge
avoidwork Mar 29, 2026
c99834b
docs: update package.json description to match README tagline
avoidwork Mar 29, 2026
923683d
docs: optimize package.json keywords for discoverability
avoidwork Mar 29, 2026
b5eb5c4
chore: update files array to explicitly list lru.d.ts
avoidwork Mar 29, 2026
b7eacfd
docs: add contributing guide
avoidwork Mar 29, 2026
1afa568
docs: update AGENTS.md with correct npm scripts
avoidwork Mar 29, 2026
d0f5992
docs: update AGENTS.md development workflow section
avoidwork Mar 29, 2026
2351d32
docs: rename ESLint Configuration to Lint Configuration
avoidwork Mar 29, 2026
9a9788f
types: update set() and setWithEvicted() signatures to remove unused …
avoidwork Mar 29, 2026
f69680e
docs: fix TypeScript signatures in TECHNICAL_DOCUMENTATION.md to matc…
avoidwork Mar 29, 2026
08335be
docs: fix TTL reset invariant and expiry formula in technical documen…
avoidwork Mar 29, 2026
93465ff
perf: remove bypass parameter from evict() to avoid V8 deoptimization
avoidwork Mar 29, 2026
05482df
docs: fix resetTtl description and setWithEvicted return type
avoidwork Mar 29, 2026
65a1785
build: update distribution files
avoidwork Mar 29, 2026
72a2dd2
refactor: make unlink() private and update Node.js version requirement
avoidwork Mar 29, 2026
ee7cdc2
refactor: simplify JSDoc by removing @example, @see, @since, @method,…
avoidwork Mar 29, 2026
00fea20
test: update tests to match current API and add edge case coverage
avoidwork Mar 29, 2026
7d409e8
docs: update Node.js version requirement to 14+ and fix test runner r…
avoidwork Mar 29, 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.

2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

npm test
npm run fix && npm run coverage && git add -A
5 changes: 5 additions & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "./node_modules/oxfmt/configuration_schema.json",
"ignorePatterns": [],
"useTabs": true
}
84 changes: 84 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# 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 coverage # Run tests with coverage reporting
npm run fix # Fix linting and formatting issues
npm run lint # Lint code with oxlint
```

## Development Workflow

Source code is in `src/`.

- **lint**: Check and fix linting issues with oxlint
- **fix**: Fix linting and formatting issues
- **build**: Lint + rollup build
- **coverage**: 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)

## Development Principles

- **DRY (Don't Repeat Yourself)**: Extract common logic into reusable functions; avoid duplication
- **YAGNI (You Ain't Gonna Need It)**: Implement only what's needed; avoid over-engineering
- **SOLID**: Follow single responsibility, open/closed, and interface segregation principles
- **OWASP**: Prioritize security; avoid unsafe operations, validate inputs, prevent injection risks

## 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%
- Test pattern: `tests/**/*.js`
- All tests must pass with 100% coverage before merging
- Run: `npm test` (lint + tests) or `npm run coverage` for coverage report

## 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
> 10 February 2017

- Changing the signature of `remove()` to avoid edge case creation [`bb88a78`](https://github.com/avoidwork/tiny-lru/commit/bb88a78366f1ae4af209025810e0409f77ff67dc)
- Adding some tests double checking deleting things that don't exist won''t be an issue [`e208b76`](https://github.com/avoidwork/tiny-lru/commit/e208b7601c1b31e59ebca94cd320ad8d1b40a067)
- Adding some tests double checking deleting things that don't exist won''t be an issue [`e208b76`](https://github.com/avoidwork/tiny-lru/commit/e208b7601c1b31e59ebca94cd320ad8d1b40a067)

#### [1.4.2](https://github.com/avoidwork/tiny-lru/compare/1.4.1...1.4.2)

Expand Down
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@AGENTS.md
112 changes: 112 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Contributing to tiny-lru

Thank you for your interest in contributing to tiny-lru! This document outlines the process for contributing to the project.

## Code of Conduct

This project follows the [Contributor Covenant](https://www.contributor-covenant.org/) code of conduct. By participating, you are expected to uphold this code.

## Getting Started

1. Fork the repository
2. Clone your fork: `git clone https://github.com/YOUR_USERNAME/tiny-lru.git`
3. Install dependencies: `npm install`
4. Create a branch: `git checkout -b feature/your-feature-name`

## Development

### Setup

```bash
npm install
```

### Running Tests

```bash
npm test # Run lint and tests
npm run mocha # Run tests with coverage
```

### Code Style

- **Indentation**: Tabs
- **Quotes**: Double quotes
- **Semicolons**: Required
- **Formatting**: Run `npm run fix` before committing

### Linting and Formatting

```bash
npm run lint # Check linting and formatting
npm run fix # Fix linting and formatting issues
```

## Making Changes

### Guiding Principles

- **DRY (Don't Repeat Yourself)**: Extract common logic into reusable functions
- **YAGNI (You Ain't Gonna Need It)**: Implement only what's needed
- **SOLID**: Follow single responsibility, open/closed, and interface segregation principles
- **OWASP**: Prioritize security; validate inputs, avoid unsafe operations

### Writing Tests

- All new features must include tests
- Maintain 100% line coverage
- Tests live in `tests/unit/`
- Run `npm run mocha` to verify coverage

### Commit Messages

Follow conventional commits:

```
type(scope): description

[optional body]

[optional footer]
```

**Types**: `feat`, `fix`, `docs`, `style`, `refactor`, `test`, `chore`

**Examples**:
```
feat: add setWithEvicted method
fix: correct TTL expiration check
docs: update README API reference
```

## Pull Request Process

1. Ensure all tests pass: `npm test`
2. Ensure 100% test coverage: `npm run mocha`
3. Update documentation if needed
4. Squash commits if necessary
5. Submit pull request with clear description

### PR Checklist

- [ ] Tests pass with `npm test`
- [ ] 100% code coverage maintained
- [ ] Linting passes with `npm run lint`
- [ ] Documentation updated
- [ ] No breaking changes (or clearly documented)

## Releasing

Releases are managed by the maintainers. If you're preparing a release:

1. Update version in `package.json`
2. Update `CHANGELOG.md`
3. Create release tag

## Questions?

Open an issue for any questions or discussions about contributions.

## License

By contributing, you agree that your contributions will be licensed under the BSD-3-Clause license.
Loading
Loading