From 86e4c7565caa9d18088ff5774682ce20d44169b1 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Tue, 8 Aug 2017 22:51:37 +0200 Subject: [PATCH] [quick-lru] introduce typings (#18730) --- types/quick-lru/index.d.ts | 26 ++++++++++++++++++++++++++ types/quick-lru/quick-lru-tests.ts | 29 +++++++++++++++++++++++++++++ types/quick-lru/tsconfig.json | 23 +++++++++++++++++++++++ types/quick-lru/tslint.json | 1 + 4 files changed, 79 insertions(+) create mode 100644 types/quick-lru/index.d.ts create mode 100644 types/quick-lru/quick-lru-tests.ts create mode 100644 types/quick-lru/tsconfig.json create mode 100644 types/quick-lru/tslint.json diff --git a/types/quick-lru/index.d.ts b/types/quick-lru/index.d.ts new file mode 100644 index 0000000000..7ce12e397c --- /dev/null +++ b/types/quick-lru/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for quick-lru 1.1 +// Project: https://github.com/sindresorhus/quick-lru#readme +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = QuickLRU; + +declare class QuickLRU implements Iterable<[K, V]> { + readonly size: number; + constructor(options?: QuickLRU.Options); + [Symbol.iterator](): Iterator<[K, V]>; + set(key: K, value: V): this; + get(key: K): V | undefined; + has(key: K): boolean; + peek(key: K): V | undefined; + delete(key: K): void; + clear(): void; + keys(): Iterable; + values(): Iterable; +} + +declare namespace QuickLRU { + interface Options { + maxSize: number; + } +} diff --git a/types/quick-lru/quick-lru-tests.ts b/types/quick-lru/quick-lru-tests.ts new file mode 100644 index 0000000000..140e25bcd8 --- /dev/null +++ b/types/quick-lru/quick-lru-tests.ts @@ -0,0 +1,29 @@ +import QuickLRU = require('quick-lru'); + +let num: number; +let numu: number | undefined; +let str: string; +let bool: boolean; + +const lru = new QuickLRU({maxSize: 1000}); + +lru.set('🦄', 1).set('🌈', 2); +numu = lru.get('🦄'); +bool = lru.has('🦄'); +numu = lru.peek('🦄'); +lru.delete('🦄'); +lru.clear(); +num = lru.size; + +for (const [key, value] of lru) { + str = key; + num = value; +} + +for (const key of lru.keys()) { + str = key; +} + +for (const value of lru.values()) { + num = value; +} diff --git a/types/quick-lru/tsconfig.json b/types/quick-lru/tsconfig.json new file mode 100644 index 0000000000..0678d18c4c --- /dev/null +++ b/types/quick-lru/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es2015", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "quick-lru-tests.ts" + ] +} diff --git a/types/quick-lru/tslint.json b/types/quick-lru/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/quick-lru/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }