Skip to content

Commit

Permalink
feat: add type definitions (#4)
Browse files Browse the repository at this point in the history
* add TypeScript typings

* Apply suggestions from code review

Co-authored-by: Luke Edwards <[email protected]>
  • Loading branch information
chocolateboy and lukeed authored Sep 8, 2020
1 parent 9cd75ab commit 2e5c7f8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
14 changes: 14 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
declare interface Options {
max?: number;
maxAge?: number;
stale?: boolean;
}

declare class Cache<K, V> extends Map<K, V> {
constructor(options?: Options | number);
get(key: K, refresh?: boolean): V | undefined;
peek(key: K): V | undefined;
set(key: K, value: V, maxAge?: number): this;
}

export = Cache;
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"name": "tmp-cache",
"version": "1.0.0",
"repository": "lukeed/tmp-cache",
"description": "A least-recently-used cache manager in 35 lines of code",
"description": "A least-recently-used cache in 35 lines of code",
"main": "lib/index.js",
"types": "index.d.ts",
"license": "MIT",
"author": {
"name": "Luke Edwards",
Expand All @@ -17,6 +18,7 @@
"test": "tape test/*.js | tap-spec"
},
"files": [
"*.d.ts",
"lib"
],
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# tmp-cache [![Build Status](https://travis-ci.org/lukeed/tmp-cache.svg?branch=master)](https://travis-ci.org/lukeed/tmp-cache)

> A least-recently-used cache manager in 35 lines of code~!
> A least-recently-used cache in 35 lines of code~!
LRU caches operate on a first-in-first-out queue. This means that the first item is the oldest and will therefore be deleted once the `max` limit has been reached.

Expand Down

0 comments on commit 2e5c7f8

Please sign in to comment.