From 01b7049c180f3e283dad69ce88fba78baf67bc21 Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Mon, 28 Apr 2014 23:35:04 +0200 Subject: [PATCH] added definitions for lru-cache --- lru-cache/lru-cache-tests.ts | 56 ++++++++++++++++++++++++++++++++++++ lru-cache/lru-cache.d.ts | 34 ++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 lru-cache/lru-cache-tests.ts create mode 100644 lru-cache/lru-cache.d.ts diff --git a/lru-cache/lru-cache-tests.ts b/lru-cache/lru-cache-tests.ts new file mode 100644 index 000000000..9121ca791 --- /dev/null +++ b/lru-cache/lru-cache-tests.ts @@ -0,0 +1,56 @@ +/// + +import lru = require('lru-cache'); + +var x: any; +var num: number; +var bool: boolean; +var key: string; +var strArr: string[]; + +interface Foo { + foo(): void; +} + +var foo: Foo; +var fooArr: Foo[]; + +var opts: lru.Options; +opts = { + max: num, + maxAge: num, + stale: bool +}; +var cache: lru.Cache = lru({ + max: num, + maxAge: num, + length: (value: Foo) => { + return num + }, + dispose: (key: string, value: Foo) => { + + }, + stale: bool +}); + +cache = lru(num); + +cache.set(key, foo); +foo = cache.get(key); +foo = cache.peek(key); +bool = cache.has(key); +cache.del(key); +cache.reset(); + +cache.forEach((value: Foo, key: string, cache: lru.Cache) => { + +}); +cache.forEach((value: Foo, key: string, cache: lru.Cache) => { + +}, x); +cache.forEach((value, key, cache) => { + foo = cache.peek(key); +}); + +strArr = cache.keys(); +fooArr = cache.values(); diff --git a/lru-cache/lru-cache.d.ts b/lru-cache/lru-cache.d.ts new file mode 100644 index 000000000..ae028a553 --- /dev/null +++ b/lru-cache/lru-cache.d.ts @@ -0,0 +1,34 @@ +// Type definitions for lru-cache v2.5.0 +// Project: https://github.com/isaacs/node-lru-cache +// Definitions by: Bart van der Schoor +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module 'lru-cache' { + function LRU(opts: LRU.Options): LRU.Cache; + function LRU(max: number): LRU.Cache; + + module LRU { + interface Options { + max?: number; + maxAge?: number; + length?: (value: T) => number; + dispose?: (key: string, value: T) => void; + stale?: boolean; + } + + interface Cache { + set(key: string, value: T): void; + get(key: string): T; + peek(key: string): T; + has(key: string): boolean + del(key: string): void; + reset(): void; + forEach(iter: (value: T, key: string, cache: Cache) => void, thisp?: any): void; + + keys(): string[]; + values(): T[]; + } + } + + export = LRU; +}