mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
[sha-1] Strongly type the output using overloads. (#35645)
See options doc at https://github.com/pvorb/node-sha1.
This commit is contained in:
committed by
Ryan Cavanaugh
parent
11994525b0
commit
4b589cecf4
13
types/sha1/index.d.ts
vendored
13
types/sha1/index.d.ts
vendored
@@ -12,10 +12,19 @@
|
||||
* @param options - an options object
|
||||
* @returns the resultant SHA1 hash of the given message
|
||||
*/
|
||||
declare function main(message: string | Buffer, options?: Sha1AsStringOptions): string;
|
||||
declare function main(message: string | Buffer, options?: Sha1AsBytesOptions): Uint8Array;
|
||||
declare function main(message: string | Buffer, options?: Sha1Options): string | Uint8Array;
|
||||
export = main;
|
||||
|
||||
interface Sha1Options {
|
||||
asBytes?: boolean;
|
||||
interface Sha1AsStringOptions {
|
||||
asBytes?: false;
|
||||
asString?: boolean;
|
||||
}
|
||||
|
||||
interface Sha1AsBytesOptions {
|
||||
asBytes: true;
|
||||
asString?: false;
|
||||
}
|
||||
|
||||
type Sha1Options = Sha1AsStringOptions | Sha1AsBytesOptions;
|
||||
|
||||
@@ -9,3 +9,7 @@ const testThree = sha1('message', {asBytes: true});
|
||||
fs.readFile('sha1.d.ts', (err: Error, buf: Buffer) => {
|
||||
console.log(sha1(buf));
|
||||
});
|
||||
|
||||
const asHexString: string = sha1('message');
|
||||
const asBinString: string = sha1('message', {asString: true});
|
||||
const asBytes: Uint8Array = sha1('message', {asBytes: true});
|
||||
|
||||
Reference in New Issue
Block a user