Skip to content

Commit 7739d25

Browse files
authored
🤖 Merge PR DefinitelyTyped#72792 update 0.8.3 by @coldzonelin
1 parent 7bea06a commit 7739d25

File tree

3 files changed

+173
-34
lines changed

3 files changed

+173
-34
lines changed

types/js-md5/index.d.ts

Lines changed: 167 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,171 @@
11
declare namespace md5 {
2-
type message = string | any[] | Uint8Array | ArrayBuffer;
3-
4-
interface Md5 {
5-
array(): number[];
6-
arrayBuffer(): ArrayBuffer;
7-
buffer(): ArrayBuffer;
8-
digest(): number[];
9-
hex(): string;
10-
toString(): string;
11-
update(message: message): Md5;
12-
base64(): string;
13-
}
14-
15-
interface md5 {
16-
(message: message): string;
17-
hex(message: message): string;
18-
array(message: message): number[];
19-
digest(message: message): number[];
20-
arrayBuffer(message: message): ArrayBuffer;
21-
buffer(message: message): ArrayBuffer;
22-
create(): Md5;
23-
update(message: message): Md5;
24-
base64(message: message): string;
25-
}
2+
type Message = string | number[] | ArrayBuffer | Uint8Array;
3+
4+
interface Hasher {
5+
/**
6+
* Update hash
7+
*
8+
* @param message The message you want to hash.
9+
*/
10+
update(message: Message): Hasher;
11+
12+
/**
13+
* Return hash in hex string.
14+
*/
15+
hex(): string;
16+
17+
/**
18+
* Return hash in hex string.
19+
*/
20+
toString(): string;
21+
22+
/**
23+
* Return hash in ArrayBuffer.
24+
*/
25+
arrayBuffer(): ArrayBuffer;
26+
27+
/**
28+
* Return hash in integer array.
29+
*/
30+
digest(): number[];
31+
32+
/**
33+
* Return hash in integer array.
34+
*/
35+
array(): number[];
36+
37+
/**
38+
* Return hash in base64 string.
39+
*/
40+
base64(): string;
41+
}
42+
43+
interface Hmac {
44+
/**
45+
* Computes a Hash-based message authentication code (HMAC) using a secret key
46+
*
47+
* @param secretKey The Secret Key
48+
* @param message The message you want to hash.
49+
*/
50+
(secretKey: Message, message: Message): string;
51+
52+
/**
53+
* Create a hash object using a secret key.
54+
*
55+
* @param secretKey The Secret Key
56+
*/
57+
create(secretKey: Message): Hasher;
58+
59+
/**
60+
* Create a hash object and hash message using a secret key
61+
*
62+
* @param secretKey The Secret Key
63+
* @param message The message you want to hash.
64+
*/
65+
update(secretKey: Message, message: Message): Hasher;
66+
67+
/**
68+
* Return hash in hex string.
69+
*
70+
* @param secretKey The Secret Key
71+
* @param message The message you want to hash.
72+
*/
73+
hex(secretKey: Message, message: Message): string;
74+
75+
/**
76+
* Return hash in ArrayBuffer.
77+
*
78+
* @param secretKey The Secret Key
79+
* @param message The message you want to hash.
80+
*/
81+
arrayBuffer(secretKey: Message, message: Message): ArrayBuffer;
82+
83+
/**
84+
* Return hash in integer array.
85+
*
86+
* @param secretKey The Secret Key
87+
* @param message The message you want to hash.
88+
*/
89+
digest(secretKey: Message, message: Message): number[];
90+
91+
/**
92+
* Return hash in integer array.
93+
*
94+
* @param secretKey The Secret Key
95+
* @param message The message you want to hash.
96+
*/
97+
array(secretKey: Message, message: Message): number[];
98+
99+
/**
100+
* Return hash in base64 string.
101+
*
102+
* @param secretKey The Secret Key
103+
* @param message The message you want to hash.
104+
*/
105+
base64(secretKey: Message, message: Message): string;
106+
}
107+
108+
interface Hash {
109+
/**
110+
* Hash and return hex string.
111+
*
112+
* @param message The message you want to hash.
113+
*/
114+
(message: Message): string;
115+
116+
/**
117+
* Create a hash object.
118+
*/
119+
create(): Hasher;
120+
121+
/**
122+
* Create a hash object and hash message.
123+
*
124+
* @param message The message you want to hash.
125+
*/
126+
update(message: Message): Hasher;
127+
128+
/**
129+
* Return hash in hex string.
130+
*
131+
* @param message The message you want to hash.
132+
*/
133+
hex(message: Message): string;
134+
135+
/**
136+
* Return hash in ArrayBuffer.
137+
*
138+
* @param message The message you want to hash.
139+
*/
140+
arrayBuffer(message: Message): ArrayBuffer;
141+
142+
/**
143+
* Return hash in integer array.
144+
*
145+
* @param message The message you want to hash.
146+
*/
147+
digest(message: Message): number[];
148+
149+
/**
150+
* Return hash in integer array.
151+
*
152+
* @param message The message you want to hash.
153+
*/
154+
array(message: Message): number[];
155+
156+
/**
157+
* Return hash in base64 string.
158+
*
159+
* @param message The message you want to hash.
160+
*/
161+
base64(message: Message): string;
162+
163+
/**
164+
* HMAC interface
165+
*/
166+
hmac: Hmac;
167+
}
26168
}
27169

28-
declare const md5: md5.md5;
170+
declare const md5: md5.Hash;
29171
export = md5;

types/js-md5/js-md5-tests.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ str = md5("The quick brown fox jumps over the lazy dog");
55
let arr: number[] = md5.digest("The quick brown fox jumps over the lazy dog");
66
arr = md5.array("The quick brown fox jumps over the lazy dog");
77
let buf: ArrayBuffer = md5.arrayBuffer("The quick brown fox jumps over the lazy dog");
8-
buf = md5.buffer("The quick brown fox jumps over the lazy dog");
98
md5.base64("The quick brown fox jumps over the lazy dog");
109

11-
// $ExpectType Md5
10+
// $ExpectType Hasher
1211
const hash1 = md5.create();
13-
// $ExpectType Md5
12+
// $ExpectType Hasher
1413
hash1.update("The quick brown fox jumps over the lazy dog");
1514
// $ExpectType string
1615
str = hash1.hex();
@@ -22,10 +21,9 @@ arr = hash1.digest();
2221
arr = hash1.array();
2322
// $ExpectType ArrayBuffer
2423
buf = hash1.arrayBuffer();
25-
// $ExpectType ArrayBuffer
26-
buf = hash1.buffer();
2724

28-
// $ExpectType Md5
25+
26+
// $ExpectType Hasher
2927
const hash2 = md5.update("The quick brown fox jumps over the lazy dog");
3028
// $ExpectType string
3129
str = hash2.hex();
@@ -37,8 +35,7 @@ arr = hash2.digest();
3735
arr = hash2.array();
3836
// $ExpectType ArrayBuffer
3937
buf = hash2.arrayBuffer();
40-
// $ExpectType ArrayBuffer
41-
buf = hash2.buffer();
38+
4239

4340
// $ExpectType string
4441
str = md5([]);

types/js-md5/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/js-md5",
4-
"version": "0.7.9999",
4+
"version": "0.8.9999",
55
"projects": [
66
"https://github.com/emn178/js-md5"
77
],

0 commit comments

Comments
 (0)