[quick-lru] introduce typings (#18730)

This commit is contained in:
Dimitri Benin
2017-08-08 13:51:37 -07:00
committed by Mohamed Hegazy
parent a0d20a1314
commit 86e4c7565c
4 changed files with 79 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
// Type definitions for quick-lru 1.1
// Project: https://github.com/sindresorhus/quick-lru#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = QuickLRU;
declare class QuickLRU<K, V> 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<K>;
values(): Iterable<V>;
}
declare namespace QuickLRU {
interface Options {
maxSize: number;
}
}
+29
View File
@@ -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<string, number>({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;
}
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }