diff --git a/types/hasha/hasha-tests.ts b/types/hasha/hasha-tests.ts new file mode 100644 index 0000000000..d0054de81a --- /dev/null +++ b/types/hasha/hasha-tests.ts @@ -0,0 +1,19 @@ +import hasha = require('hasha'); + +let str: string | null; +let buf: Buffer | null; + +str = hasha('unicorn'); +str = hasha('unicorn', {algorithm: 'md5'}); +str = hasha('unicorn', {algorithm: 'md5', encoding: 'latin1'}); +buf = hasha('unicorn', {algorithm: 'md5', encoding: 'buffer'}); + +process.stdin.pipe(hasha.stream()).pipe(process.stdout); + +hasha.fromStream(process.stdin).then(hash => str = hash); +hasha.fromStream(process.stdin, {encoding: 'hex'}).then(hash => str = hash); +hasha.fromStream(process.stdin, {encoding: 'buffer'}).then(hash => buf = hash); + +hasha.fromFile('unicorn.png').then(hash => str = hash); +hasha.fromFile('unicorn.png', {encoding: 'base64'}).then(hash => str = hash); +hasha.fromFile('unicorn.png', {encoding: 'buffer'}).then(hash => buf = hash); diff --git a/types/hasha/index.d.ts b/types/hasha/index.d.ts new file mode 100644 index 0000000000..a158af88a3 --- /dev/null +++ b/types/hasha/index.d.ts @@ -0,0 +1,38 @@ +// Type definitions for hasha 3.0 +// Project: https://github.com/sindresorhus/hasha +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +import * as crypto from "crypto"; + +export = hasha; + +declare function hasha(input: hasha.HashaInput): string; +declare function hasha(input: hasha.HashaInput, options: hasha.HashaOptions): string; +declare function hasha(input: hasha.HashaInput, options: hasha.HashaOptions): Buffer; + +declare namespace hasha { + type HashaInput = string | string[] | Buffer | Buffer[]; + type ToStringEncoding = 'hex' | 'base64' | 'latin1' | 'binary' | undefined; + type HashaEncoding = ToStringEncoding | 'buffer'; + + interface HashaOptions { + encoding?: E; + algorithm?: string; + } + + function stream(options?: HashaOptions): crypto.Hash; + + function fromStream(stream: NodeJS.ReadableStream): Promise; + function fromStream(stream: NodeJS.ReadableStream, options?: HashaOptions): Promise; + function fromStream(stream: NodeJS.ReadableStream, options?: HashaOptions): Promise; + + function fromFile(filePath: string): Promise; + function fromFile(filePath: string, options: HashaOptions): Promise; + function fromFile(filePath: string, options: HashaOptions): Promise; + + function fromFileSync(filePath: string): string; + function fromFileSync(filePath: string, options: HashaOptions): string; + function fromFileSync(filePath: string, options: HashaOptions): Buffer; +} diff --git a/types/hasha/tsconfig.json b/types/hasha/tsconfig.json new file mode 100644 index 0000000000..3aeb5973e8 --- /dev/null +++ b/types/hasha/tsconfig.json @@ -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", + "hasha-tests.ts" + ] +} diff --git a/types/hasha/tslint.json b/types/hasha/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/hasha/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }