diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..c2f7256 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,14 @@ +declare interface Options { + max?: number; + maxAge?: number; + stale?: boolean; +} + +declare class Cache extends Map { + 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; diff --git a/package.json b/package.json index 5c29438..9999721 100644 --- a/package.json +++ b/package.json @@ -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", @@ -17,6 +18,7 @@ "test": "tape test/*.js | tap-spec" }, "files": [ + "*.d.ts", "lib" ], "keywords": [ diff --git a/readme.md b/readme.md index f2798b1..795ce41 100644 --- a/readme.md +++ b/readme.md @@ -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.