From 5dafc2c0f60bbc8e8d103e0c76ae502e2e26d489 Mon Sep 17 00:00:00 2001 From: Arne Schubert Date: Tue, 1 May 2018 18:16:47 +0200 Subject: [PATCH] Adding type defintion for murmurhash module of npm (#25413) --- types/murmurhash/index.d.ts | 29 ++++++++++++++++++++++++++++ types/murmurhash/murmurhash-tests.ts | 8 ++++++++ types/murmurhash/tsconfig.json | 23 ++++++++++++++++++++++ types/murmurhash/tslint.json | 1 + 4 files changed, 61 insertions(+) create mode 100644 types/murmurhash/index.d.ts create mode 100644 types/murmurhash/murmurhash-tests.ts create mode 100644 types/murmurhash/tsconfig.json create mode 100644 types/murmurhash/tslint.json diff --git a/types/murmurhash/index.d.ts b/types/murmurhash/index.d.ts new file mode 100644 index 0000000000..31c663fd33 --- /dev/null +++ b/types/murmurhash/index.d.ts @@ -0,0 +1,29 @@ +// Type definitions for murmurhash 0.0 +// Project: https://github.com/perezd/node-murmurhash +// Definitions by: Arne Schubert +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = murmurhash; + +/** + * JS Implementation of MurmurHash3 (r136) (as of May 20, 2011) + * + * @param key - ASCII only + * @param seed - Positive integer only + * @return - 32-bit positive integer hash + */ +declare function murmurhash(key: string, seed: number): number; + +declare namespace murmurhash { + // Circular reference from murmurhash + function v3(key: string, seed: number): number; + + /** + * JS Implementation of MurmurHash2 + * + * @param str - ASCII only + * @param seed - Positive integer only + * @return - 32-bit positive integer hash + */ + function v2(str: string, seed: number): number; +} diff --git a/types/murmurhash/murmurhash-tests.ts b/types/murmurhash/murmurhash-tests.ts new file mode 100644 index 0000000000..ebbbf09cab --- /dev/null +++ b/types/murmurhash/murmurhash-tests.ts @@ -0,0 +1,8 @@ +import murmurhash = require('murmurhash'); + +const stringValue = "test"; +let numberValue = 123; + +numberValue = murmurhash(stringValue, numberValue); +numberValue = murmurhash.v2(stringValue, numberValue); +numberValue = murmurhash.v3(stringValue, numberValue); diff --git a/types/murmurhash/tsconfig.json b/types/murmurhash/tsconfig.json new file mode 100644 index 0000000000..1778d66a72 --- /dev/null +++ b/types/murmurhash/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "murmurhash-tests.ts" + ] +} diff --git a/types/murmurhash/tslint.json b/types/murmurhash/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/murmurhash/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }