From b0b45350bcd1c8cb7f8ed7a5b51d1bade69412f1 Mon Sep 17 00:00:00 2001 From: Sam Verschueren Date: Thu, 17 Nov 2016 11:53:35 +0100 Subject: [PATCH] add mem --- mem/index.d.ts | 18 ++++++++++++++++++ mem/mem-tests.ts | 10 ++++++++++ mem/tsconfig.json | 19 +++++++++++++++++++ mem/tslint.json | 1 + 4 files changed, 48 insertions(+) create mode 100644 mem/index.d.ts create mode 100644 mem/mem-tests.ts create mode 100644 mem/tsconfig.json create mode 100644 mem/tslint.json diff --git a/mem/index.d.ts b/mem/index.d.ts new file mode 100644 index 0000000000..3ba85ce926 --- /dev/null +++ b/mem/index.d.ts @@ -0,0 +1,18 @@ +// Type definitions for mem 1.1.0 +// Project: https://github.com/sindresorhus/mem +// Definitions by: Sam Verschueren +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface Options { + maxAge?: number; + cacheKey?: (...args: any[]) => string; + cache?: any; +} + +declare const mem: { + any>(fn: F, options?: Options): F; + clear any>(fn: F): void; +}; + +declare namespace mem { } +export = mem; diff --git a/mem/mem-tests.ts b/mem/mem-tests.ts new file mode 100644 index 0000000000..efa6214fca --- /dev/null +++ b/mem/mem-tests.ts @@ -0,0 +1,10 @@ +import * as mem from 'mem'; + +let i = 0; +const memoized = mem((arg: string) => ++i); +const ret1: number = memoized('foo'); + +// Clear the memoized data +mem.clear(memoized); + +const ret2: Promise = mem(() => Promise.resolve('foo'))(); diff --git a/mem/tsconfig.json b/mem/tsconfig.json new file mode 100644 index 0000000000..65d9a6999c --- /dev/null +++ b/mem/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "mem-tests.ts" + ] +} \ No newline at end of file diff --git a/mem/tslint.json b/mem/tslint.json new file mode 100644 index 0000000000..2221e40e4a --- /dev/null +++ b/mem/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } \ No newline at end of file