Merge pull request #2121 from Bartvds/def/lru-cache

added definitions for lru-cache
This commit is contained in:
Bart van der Schoor
2014-04-29 17:20:21 +02:00
2 changed files with 90 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
/// <reference path="lru-cache.d.ts" />
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<any>;
opts = {
max: num,
maxAge: num,
stale: bool
};
var cache: lru.Cache<Foo> = lru<Foo>({
max: num,
maxAge: num,
length: (value: Foo) => {
return num
},
dispose: (key: string, value: Foo) => {
},
stale: bool
});
cache = lru<Foo>(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<Foo>) => {
});
cache.forEach((value: Foo, key: string, cache: lru.Cache<Foo>) => {
}, x);
cache.forEach((value, key, cache) => {
foo = cache.peek(key);
});
strArr = cache.keys();
fooArr = cache.values();
+34
View File
@@ -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 <https://github.com/Bartvds>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module 'lru-cache' {
function LRU<T>(opts: LRU.Options<T>): LRU.Cache<T>;
function LRU<T>(max: number): LRU.Cache<T>;
module LRU {
interface Options<T> {
max?: number;
maxAge?: number;
length?: (value: T) => number;
dispose?: (key: string, value: T) => void;
stale?: boolean;
}
interface Cache<T> {
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<T>) => void, thisp?: any): void;
keys(): string[];
values(): T[];
}
}
export = LRU;
}