Merge pull request #17933 from bastienmoulia/spark-md5

[spark-md5] Add types
This commit is contained in:
Ryan Cavanaugh
2017-07-14 00:57:28 -07:00
committed by GitHub
4 changed files with 90 additions and 0 deletions

42
types/spark-md5/index.d.ts vendored Normal file
View File

@@ -0,0 +1,42 @@
// Type definitions for spark-md5 3.0
// Project: https://github.com/satazor/js-spark-md5#readme
// Definitions by: Bastien Moulia <https://github.com/bastienmoulia>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
interface State {
buff: Uint8Array;
length: number;
hash: number[];
}
// copy of ArrayBuffer because of a conflict with the class SparkMD5.ArrayBuffer
interface ArrayBufferCopy extends ArrayBuffer {}
declare class SparkMD5 {
constructor();
append(str: string): SparkMD5;
appendBinary(contents: string): SparkMD5;
end(raw?: boolean): string;
reset(): SparkMD5;
getState(): State;
setState(state: State): State;
destroy(): void;
static hash(str: string, raw?: boolean): string;
static hashBinary(content: string, raw?: boolean): string;
}
declare namespace SparkMD5 {
class ArrayBuffer {
constructor();
append(str: string): ArrayBuffer;
end(raw?: boolean): string;
reset(): ArrayBuffer;
getState(): State;
setState(state: State): State;
destroy(): void;
static hash(arr: ArrayBufferCopy, raw?: boolean): string;
}
}
export = SparkMD5;

View File

@@ -0,0 +1,20 @@
import * as SparkMD5 from "spark-md5";
SparkMD5.hash('Hi there');
SparkMD5.hash('Hi there', true);
SparkMD5.hashBinary("");
let spark = new SparkMD5();
spark.append('Hi');
spark.append(' there');
let hexHash = spark.end();
let rawHash = spark.end(true);
let sparkArr = new SparkMD5.ArrayBuffer();
sparkArr.append('Hi');
sparkArr.append(' there');
hexHash = sparkArr.end();
rawHash = sparkArr.end(true);
const arr = new ArrayBuffer(8);
SparkMD5.ArrayBuffer.hash(arr);

View File

@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"spark-md5-tests.ts"
]
}

View File

@@ -0,0 +1,6 @@
{
"extends": "dtslint/dt.json",
"rules": {
"no-empty-interface": false
}
}