mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
[hasha] introduce typings (#18284)
This commit is contained in:
committed by
Wesley Wigham
parent
379d9ca112
commit
0dd0b27c90
19
types/hasha/hasha-tests.ts
Normal file
19
types/hasha/hasha-tests.ts
Normal file
@@ -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);
|
||||
38
types/hasha/index.d.ts
vendored
Normal file
38
types/hasha/index.d.ts
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
// Type definitions for hasha 3.0
|
||||
// Project: https://github.com/sindresorhus/hasha
|
||||
// Definitions by: BendingBender <https://github.com/BendgingBender>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node"/>
|
||||
import * as crypto from "crypto";
|
||||
|
||||
export = hasha;
|
||||
|
||||
declare function hasha(input: hasha.HashaInput): string;
|
||||
declare function hasha<E extends hasha.ToStringEncoding>(input: hasha.HashaInput, options: hasha.HashaOptions<E>): string;
|
||||
declare function hasha<E extends 'buffer'>(input: hasha.HashaInput, options: hasha.HashaOptions<E>): Buffer;
|
||||
|
||||
declare namespace hasha {
|
||||
type HashaInput = string | string[] | Buffer | Buffer[];
|
||||
type ToStringEncoding = 'hex' | 'base64' | 'latin1' | 'binary' | undefined;
|
||||
type HashaEncoding = ToStringEncoding | 'buffer';
|
||||
|
||||
interface HashaOptions<E extends HashaEncoding> {
|
||||
encoding?: E;
|
||||
algorithm?: string;
|
||||
}
|
||||
|
||||
function stream(options?: HashaOptions<HashaEncoding>): crypto.Hash;
|
||||
|
||||
function fromStream(stream: NodeJS.ReadableStream): Promise<string | null>;
|
||||
function fromStream<E extends ToStringEncoding>(stream: NodeJS.ReadableStream, options?: HashaOptions<E>): Promise<string | null>;
|
||||
function fromStream<E extends 'buffer'>(stream: NodeJS.ReadableStream, options?: HashaOptions<E>): Promise<Buffer | null>;
|
||||
|
||||
function fromFile(filePath: string): Promise<string | null>;
|
||||
function fromFile<E extends ToStringEncoding>(filePath: string, options: HashaOptions<E>): Promise<string | null>;
|
||||
function fromFile<E extends 'buffer'>(filePath: string, options: HashaOptions<E>): Promise<Buffer | null>;
|
||||
|
||||
function fromFileSync(filePath: string): string;
|
||||
function fromFileSync<E extends ToStringEncoding>(filePath: string, options: HashaOptions<E>): string;
|
||||
function fromFileSync<E extends 'buffer'>(filePath: string, options: HashaOptions<E>): Buffer;
|
||||
}
|
||||
22
types/hasha/tsconfig.json
Normal file
22
types/hasha/tsconfig.json
Normal 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",
|
||||
"hasha-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/hasha/tslint.json
Normal file
1
types/hasha/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user