@ivujs/i-utils 1.1.18 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/README.md +122 -58
  2. package/dist/cjs/ID-card/index.cjs +95 -0
  3. package/dist/cjs/array/index.cjs +476 -0
  4. package/dist/cjs/clipboard/index.cjs +132 -0
  5. package/dist/cjs/color/index.cjs +207 -0
  6. package/dist/cjs/constants/date.cjs +178 -0
  7. package/dist/cjs/constants/id-card.cjs +52 -0
  8. package/dist/cjs/constants/keycode.cjs +117 -0
  9. package/dist/cjs/constants/lang.cjs +13 -0
  10. package/dist/cjs/constants/math.cjs +13 -0
  11. package/dist/cjs/constants/regexp.cjs +53 -0
  12. package/dist/cjs/constants/sort.cjs +15 -0
  13. package/dist/cjs/cookie/index.cjs +73 -0
  14. package/dist/cjs/crypto/base64/base64.cjs +540 -0
  15. package/dist/cjs/crypto/base64/index.cjs +82 -0
  16. package/dist/cjs/crypto/md5/index.cjs +49 -0
  17. package/dist/cjs/crypto/md5/md5.cjs +351 -0
  18. package/dist/cjs/crypto/sha256/index.cjs +95 -0
  19. package/dist/cjs/crypto/sha256/sha256.cjs +557 -0
  20. package/dist/cjs/crypto/sm3/index.cjs +27 -0
  21. package/dist/cjs/crypto/sm3/sm3.cjs +200 -0
  22. package/dist/cjs/crypto/sm4/index.cjs +101 -0
  23. package/dist/cjs/crypto/sm4/sm4.cjs +498 -0
  24. package/dist/cjs/date/index.cjs +1310 -0
  25. package/dist/cjs/desensitized/index.cjs +78 -0
  26. package/dist/cjs/device/index.cjs +154 -0
  27. package/dist/cjs/dom/index.cjs +132 -0
  28. package/dist/cjs/file/index.cjs +343 -0
  29. package/dist/cjs/function/index.cjs +72 -0
  30. package/dist/cjs/id/index.cjs +6 -2
  31. package/dist/cjs/index.cjs +383 -7
  32. package/dist/cjs/keycode/index.cjs +30 -0
  33. package/dist/cjs/math/index.cjs +310 -0
  34. package/dist/cjs/number/index.cjs +34 -0
  35. package/dist/cjs/object/index.cjs +319 -0
  36. package/dist/cjs/pagination/index.cjs +146 -0
  37. package/dist/cjs/random/index.cjs +27 -0
  38. package/dist/cjs/regexp/index.cjs +103 -0
  39. package/dist/cjs/storage/index.cjs +14 -0
  40. package/dist/cjs/storage/localStorage.cjs +37 -0
  41. package/dist/cjs/storage/sessionStorage.cjs +37 -0
  42. package/dist/cjs/string/index.cjs +361 -0
  43. package/dist/cjs/url/index.cjs +261 -0
  44. package/dist/cjs/validate/index.cjs +484 -0
  45. package/dist/es/ID-card/index.d.ts +36 -0
  46. package/dist/es/ID-card/index.mjs +89 -0
  47. package/dist/es/array/index.d.ts +209 -0
  48. package/dist/es/array/index.mjs +447 -0
  49. package/dist/es/clipboard/index.d.ts +32 -0
  50. package/dist/es/clipboard/index.mjs +126 -0
  51. package/dist/es/color/index.d.ts +55 -0
  52. package/dist/es/color/index.mjs +197 -0
  53. package/dist/es/constants/date.d.ts +4 -0
  54. package/dist/es/constants/date.mjs +176 -0
  55. package/dist/es/constants/id-card.d.ts +4 -0
  56. package/dist/es/constants/id-card.mjs +50 -0
  57. package/dist/es/constants/index.d.ts +11 -0
  58. package/dist/es/constants/keycode.d.ts +1 -0
  59. package/dist/es/constants/keycode.mjs +115 -0
  60. package/dist/es/constants/lang.d.ts +4 -0
  61. package/dist/es/constants/lang.mjs +11 -0
  62. package/dist/es/constants/math.d.ts +4 -0
  63. package/dist/es/constants/math.mjs +11 -0
  64. package/dist/es/constants/regexp.d.ts +4 -0
  65. package/dist/es/constants/regexp.mjs +51 -0
  66. package/dist/es/constants/sort.d.ts +4 -0
  67. package/dist/es/constants/sort.mjs +13 -0
  68. package/dist/es/cookie/index.d.ts +29 -0
  69. package/dist/es/cookie/index.mjs +67 -0
  70. package/dist/es/crypto/base64/base64.d.ts +8 -0
  71. package/dist/es/crypto/base64/base64.mjs +531 -0
  72. package/dist/es/crypto/base64/index.d.ts +53 -0
  73. package/dist/es/crypto/base64/index.mjs +73 -0
  74. package/dist/es/crypto/index.d.ts +8 -0
  75. package/dist/es/crypto/md5/index.d.ts +26 -0
  76. package/dist/es/crypto/md5/index.mjs +44 -0
  77. package/dist/es/crypto/md5/md5.d.ts +11 -0
  78. package/dist/es/crypto/md5/md5.mjs +349 -0
  79. package/dist/es/crypto/sha256/index.d.ts +52 -0
  80. package/dist/es/crypto/sha256/index.mjs +86 -0
  81. package/dist/es/crypto/sha256/sha256.d.ts +82 -0
  82. package/dist/es/crypto/sha256/sha256.mjs +548 -0
  83. package/dist/es/crypto/sm3/index.d.ts +13 -0
  84. package/dist/es/crypto/sm3/index.mjs +24 -0
  85. package/dist/es/crypto/sm3/sm3.d.ts +3 -0
  86. package/dist/es/crypto/sm3/sm3.mjs +197 -0
  87. package/dist/es/crypto/sm4/index.d.ts +56 -0
  88. package/dist/es/crypto/sm4/index.mjs +95 -0
  89. package/dist/es/crypto/sm4/sm4.d.ts +48 -0
  90. package/dist/es/crypto/sm4/sm4.mjs +490 -0
  91. package/dist/es/date/index.d.ts +608 -0
  92. package/dist/es/date/index.mjs +1222 -0
  93. package/dist/es/desensitized/index.d.ts +41 -0
  94. package/dist/es/desensitized/index.mjs +72 -0
  95. package/dist/es/device/index.d.ts +73 -0
  96. package/dist/es/device/index.mjs +140 -0
  97. package/dist/es/dom/index.d.ts +60 -0
  98. package/dist/es/dom/index.mjs +122 -0
  99. package/dist/es/file/index.d.ts +93 -0
  100. package/dist/es/file/index.mjs +327 -0
  101. package/dist/es/function/index.d.ts +26 -0
  102. package/dist/es/function/index.mjs +68 -0
  103. package/dist/es/id/index.d.ts +3 -0
  104. package/dist/es/id/index.mjs +6 -2
  105. package/dist/es/index.d.ts +26 -2
  106. package/dist/es/index.mjs +40 -4
  107. package/dist/es/keycode/index.d.ts +12 -0
  108. package/dist/es/keycode/index.mjs +27 -0
  109. package/dist/es/math/index.d.ts +66 -0
  110. package/dist/es/math/index.mjs +300 -0
  111. package/dist/es/number/index.d.ts +14 -0
  112. package/dist/es/number/index.mjs +31 -0
  113. package/dist/es/object/index.d.ts +84 -0
  114. package/dist/es/object/index.mjs +306 -0
  115. package/dist/es/pagination/index.d.ts +67 -0
  116. package/dist/es/pagination/index.mjs +140 -0
  117. package/dist/es/random/index.d.ts +18 -0
  118. package/dist/es/random/index.mjs +24 -0
  119. package/dist/es/regexp/index.d.ts +63 -0
  120. package/dist/es/regexp/index.mjs +92 -0
  121. package/dist/es/storage/index.d.ts +13 -0
  122. package/dist/es/storage/index.mjs +12 -0
  123. package/dist/es/storage/localStorage.d.ts +21 -0
  124. package/dist/es/storage/localStorage.mjs +32 -0
  125. package/dist/es/storage/sessionStorage.d.ts +21 -0
  126. package/dist/es/storage/sessionStorage.mjs +32 -0
  127. package/dist/es/string/index.d.ts +124 -0
  128. package/dist/es/string/index.mjs +342 -0
  129. package/dist/es/url/index.d.ts +118 -0
  130. package/dist/es/url/index.mjs +243 -0
  131. package/dist/es/validate/index.d.ts +231 -0
  132. package/dist/es/validate/index.mjs +447 -0
  133. package/dist/index.d.ts +2394 -2
  134. package/dist/lib/index.full.umd.js +8059 -29
  135. package/dist/lib/index.full.umd.min.js +2 -2
  136. package/dist/lib/index.full.umd.min.js.map +1 -1
  137. package/dist/resolver/auto-imports.cjs +345 -2
  138. package/dist/resolver/auto-imports.mjs +345 -2
  139. package/dist/resolver/index.cjs +1 -2
  140. package/dist/resolver/index.d.ts +1 -1
  141. package/dist/resolver/index.mjs +1 -2
  142. package/package.json +16 -7
@@ -0,0 +1,44 @@
1
+ import { md5 as md5$1 } from './md5.mjs';
2
+
3
+ /**
4
+ * md5 加密
5
+ * @param {string} str 字符串
6
+ * @returns {string} 返回加密后的十六进制字符串
7
+ */
8
+ function md5(str) {
9
+ return md5$1(str);
10
+ }
11
+ /**
12
+ * md5 加密
13
+ * @param {string} str 字符串
14
+ * @returns {*} 返回加密后的二进制原始值
15
+ */
16
+ function md5Raw(str) {
17
+ return md5$1(str, undefined, true);
18
+ }
19
+ /**
20
+ * md5_hmac 加密
21
+ * @param {string} str 字符串
22
+ * @param {string} key 秘钥
23
+ * @returns {string} 返回加密后的十六进制字符串
24
+ */
25
+ function md5Hmac(str, key) {
26
+ if (!str || !key) {
27
+ throw new Error("Missing str or key");
28
+ }
29
+ return md5$1(str, key, false);
30
+ }
31
+ /**
32
+ * md5_hmac 加密
33
+ * @param {string} str 字符串
34
+ * @param {string} key 秘钥
35
+ * @returns {string} 返回加密后的二进制原始值
36
+ */
37
+ function md5HmacRaw(str, key) {
38
+ if (!str || !key) {
39
+ throw new Error("Missing str or key");
40
+ }
41
+ return md5$1(str, key, true);
42
+ }
43
+
44
+ export { md5, md5Hmac, md5HmacRaw, md5Raw };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Calculates MD5 value for a given string.
3
+ * If a key is provided, calculates the HMAC-MD5 value.
4
+ * Returns a Hex encoded string unless the raw argument is given.
5
+ *
6
+ * @param {string} string Input string
7
+ * @param {string} [key] HMAC key
8
+ * @param {boolean} [raw] Raw output switch
9
+ * @returns {string} MD5 output
10
+ */
11
+ export function md5(string: string, key?: string, raw?: boolean): string;
@@ -0,0 +1,349 @@
1
+ /**
2
+ * Add integers, wrapping at 2^32.
3
+ * This uses 16-bit operations internally to work around bugs in interpreters.
4
+ *
5
+ * @param {number} x First integer
6
+ * @param {number} y Second integer
7
+ * @returns {number} Sum
8
+ */
9
+ function safeAdd(x, y) {
10
+ var lsw = (x & 0xffff) + (y & 0xffff);
11
+ var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
12
+ return (msw << 16) | (lsw & 0xffff);
13
+ }
14
+ /**
15
+ * Bitwise rotate a 32-bit number to the left.
16
+ *
17
+ * @param {number} num 32-bit number
18
+ * @param {number} cnt Rotation count
19
+ * @returns {number} Rotated number
20
+ */
21
+ function bitRotateLeft(num, cnt) {
22
+ return (num << cnt) | (num >>> (32 - cnt));
23
+ }
24
+ /**
25
+ * Basic operation the algorithm uses.
26
+ *
27
+ * @param {number} q q
28
+ * @param {number} a a
29
+ * @param {number} b b
30
+ * @param {number} x x
31
+ * @param {number} s s
32
+ * @param {number} t t
33
+ * @returns {number} Result
34
+ */
35
+ function md5cmn(q, a, b, x, s, t) {
36
+ return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
37
+ }
38
+ /**
39
+ * Basic operation the algorithm uses.
40
+ *
41
+ * @param {number} a a
42
+ * @param {number} b b
43
+ * @param {number} c c
44
+ * @param {number} d d
45
+ * @param {number} x x
46
+ * @param {number} s s
47
+ * @param {number} t t
48
+ * @returns {number} Result
49
+ */
50
+ function md5ff(a, b, c, d, x, s, t) {
51
+ return md5cmn((b & c) | (~b & d), a, b, x, s, t);
52
+ }
53
+ /**
54
+ * Basic operation the algorithm uses.
55
+ *
56
+ * @param {number} a a
57
+ * @param {number} b b
58
+ * @param {number} c c
59
+ * @param {number} d d
60
+ * @param {number} x x
61
+ * @param {number} s s
62
+ * @param {number} t t
63
+ * @returns {number} Result
64
+ */
65
+ function md5gg(a, b, c, d, x, s, t) {
66
+ return md5cmn((b & d) | (c & ~d), a, b, x, s, t);
67
+ }
68
+ /**
69
+ * Basic operation the algorithm uses.
70
+ *
71
+ * @param {number} a a
72
+ * @param {number} b b
73
+ * @param {number} c c
74
+ * @param {number} d d
75
+ * @param {number} x x
76
+ * @param {number} s s
77
+ * @param {number} t t
78
+ * @returns {number} Result
79
+ */
80
+ function md5hh(a, b, c, d, x, s, t) {
81
+ return md5cmn(b ^ c ^ d, a, b, x, s, t);
82
+ }
83
+ /**
84
+ * Basic operation the algorithm uses.
85
+ *
86
+ * @param {number} a a
87
+ * @param {number} b b
88
+ * @param {number} c c
89
+ * @param {number} d d
90
+ * @param {number} x x
91
+ * @param {number} s s
92
+ * @param {number} t t
93
+ * @returns {number} Result
94
+ */
95
+ function md5ii(a, b, c, d, x, s, t) {
96
+ return md5cmn(c ^ (b | ~d), a, b, x, s, t);
97
+ }
98
+ /**
99
+ * Calculate the MD5 of an array of little-endian words, and a bit length.
100
+ *
101
+ * @param {Array} x Array of little-endian words
102
+ * @param {number} len Bit length
103
+ * @returns {Array<number>} MD5 Array
104
+ */
105
+ function binlMD5(x, len) {
106
+ /* append padding */
107
+ x[len >> 5] |= 0x80 << (len % 32);
108
+ x[(((len + 64) >>> 9) << 4) + 14] = len;
109
+ var i;
110
+ var olda;
111
+ var oldb;
112
+ var oldc;
113
+ var oldd;
114
+ var a = 1732584193;
115
+ var b = -271733879;
116
+ var c = -1732584194;
117
+ var d = 271733878;
118
+ for (i = 0; i < x.length; i += 16) {
119
+ olda = a;
120
+ oldb = b;
121
+ oldc = c;
122
+ oldd = d;
123
+ a = md5ff(a, b, c, d, x[i], 7, -680876936);
124
+ d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
125
+ c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
126
+ b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
127
+ a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
128
+ d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
129
+ c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
130
+ b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
131
+ a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
132
+ d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
133
+ c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
134
+ b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
135
+ a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
136
+ d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
137
+ c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
138
+ b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
139
+ a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
140
+ d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
141
+ c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
142
+ b = md5gg(b, c, d, a, x[i], 20, -373897302);
143
+ a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
144
+ d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
145
+ c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
146
+ b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
147
+ a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
148
+ d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
149
+ c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
150
+ b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
151
+ a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
152
+ d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
153
+ c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
154
+ b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
155
+ a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
156
+ d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
157
+ c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
158
+ b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
159
+ a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
160
+ d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
161
+ c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
162
+ b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
163
+ a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
164
+ d = md5hh(d, a, b, c, x[i], 11, -358537222);
165
+ c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
166
+ b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
167
+ a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
168
+ d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
169
+ c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
170
+ b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
171
+ a = md5ii(a, b, c, d, x[i], 6, -198630844);
172
+ d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
173
+ c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
174
+ b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
175
+ a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
176
+ d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
177
+ c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
178
+ b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
179
+ a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
180
+ d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
181
+ c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
182
+ b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
183
+ a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
184
+ d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
185
+ c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
186
+ b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
187
+ a = safeAdd(a, olda);
188
+ b = safeAdd(b, oldb);
189
+ c = safeAdd(c, oldc);
190
+ d = safeAdd(d, oldd);
191
+ }
192
+ return [a, b, c, d];
193
+ }
194
+ /**
195
+ * Convert an array of little-endian words to a string
196
+ *
197
+ * @param {Array<number>} input MD5 Array
198
+ * @returns {string} MD5 string
199
+ */
200
+ function binl2rstr(input) {
201
+ var i;
202
+ var output = "";
203
+ var length32 = input.length * 32;
204
+ for (i = 0; i < length32; i += 8) {
205
+ output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xff);
206
+ }
207
+ return output;
208
+ }
209
+ /**
210
+ * Convert a raw string to an array of little-endian words
211
+ * Characters >255 have their high-byte silently ignored.
212
+ *
213
+ * @param {string} input Raw input string
214
+ * @returns {Array<number>} Array of little-endian words
215
+ */
216
+ function rstr2binl(input) {
217
+ var i;
218
+ var output = [];
219
+ output[(input.length >> 2) - 1] = undefined;
220
+ for (i = 0; i < output.length; i += 1) {
221
+ output[i] = 0;
222
+ }
223
+ var length8 = input.length * 8;
224
+ for (i = 0; i < length8; i += 8) {
225
+ output[i >> 5] |= (input.charCodeAt(i / 8) & 0xff) << (i % 32);
226
+ }
227
+ return output;
228
+ }
229
+ /**
230
+ * Calculate the MD5 of a raw string
231
+ *
232
+ * @param {string} s Input string
233
+ * @returns {string} Raw MD5 string
234
+ */
235
+ function rstrMD5(s) {
236
+ return binl2rstr(binlMD5(rstr2binl(s), s.length * 8));
237
+ }
238
+ /**
239
+ * Calculates the HMAC-MD5 of a key and some data (raw strings)
240
+ *
241
+ * @param {string} key HMAC key
242
+ * @param {string} data Raw input string
243
+ * @returns {string} Raw MD5 string
244
+ */
245
+ function rstrHMACMD5(key, data) {
246
+ var i;
247
+ var bkey = rstr2binl(key);
248
+ var ipad = [];
249
+ var opad = [];
250
+ var hash;
251
+ ipad[15] = opad[15] = undefined;
252
+ if (bkey.length > 16) {
253
+ bkey = binlMD5(bkey, key.length * 8);
254
+ }
255
+ for (i = 0; i < 16; i += 1) {
256
+ ipad[i] = bkey[i] ^ 0x36363636;
257
+ opad[i] = bkey[i] ^ 0x5c5c5c5c;
258
+ }
259
+ hash = binlMD5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
260
+ return binl2rstr(binlMD5(opad.concat(hash), 512 + 128));
261
+ }
262
+ /**
263
+ * Convert a raw string to a hex string
264
+ *
265
+ * @param {string} input Raw input string
266
+ * @returns {string} Hex encoded string
267
+ */
268
+ function rstr2hex(input) {
269
+ var hexTab = "0123456789abcdef";
270
+ var output = "";
271
+ var x;
272
+ var i;
273
+ for (i = 0; i < input.length; i += 1) {
274
+ x = input.charCodeAt(i);
275
+ output += hexTab.charAt((x >>> 4) & 0x0f) + hexTab.charAt(x & 0x0f);
276
+ }
277
+ return output;
278
+ }
279
+ /**
280
+ * Encode a string as UTF-8
281
+ *
282
+ * @param {string} input Input string
283
+ * @returns {string} UTF8 string
284
+ */
285
+ function str2rstrUTF8(input) {
286
+ return unescape(encodeURIComponent(input));
287
+ }
288
+ /**
289
+ * Encodes input string as raw MD5 string
290
+ *
291
+ * @param {string} s Input string
292
+ * @returns {string} Raw MD5 string
293
+ */
294
+ function rawMD5(s) {
295
+ return rstrMD5(str2rstrUTF8(s));
296
+ }
297
+ /**
298
+ * Encodes input string as Hex encoded string
299
+ *
300
+ * @param {string} s Input string
301
+ * @returns {string} Hex encoded string
302
+ */
303
+ function hexMD5(s) {
304
+ return rstr2hex(rawMD5(s));
305
+ }
306
+ /**
307
+ * Calculates the raw HMAC-MD5 for the given key and data
308
+ *
309
+ * @param {string} k HMAC key
310
+ * @param {string} d Input string
311
+ * @returns {string} Raw MD5 string
312
+ */
313
+ function rawHMACMD5(k, d) {
314
+ return rstrHMACMD5(str2rstrUTF8(k), str2rstrUTF8(d));
315
+ }
316
+ /**
317
+ * Calculates the Hex encoded HMAC-MD5 for the given key and data
318
+ *
319
+ * @param {string} k HMAC key
320
+ * @param {string} d Input string
321
+ * @returns {string} Raw MD5 string
322
+ */
323
+ function hexHMACMD5(k, d) {
324
+ return rstr2hex(rawHMACMD5(k, d));
325
+ }
326
+ /**
327
+ * Calculates MD5 value for a given string.
328
+ * If a key is provided, calculates the HMAC-MD5 value.
329
+ * Returns a Hex encoded string unless the raw argument is given.
330
+ *
331
+ * @param {string} string Input string
332
+ * @param {string} [key] HMAC key
333
+ * @param {boolean} [raw] Raw output switch
334
+ * @returns {string} MD5 output
335
+ */
336
+ function md5(string, key, raw) {
337
+ if (!key) {
338
+ if (!raw) {
339
+ return hexMD5(string);
340
+ }
341
+ return rawMD5(string);
342
+ }
343
+ if (!raw) {
344
+ return hexHMACMD5(key, string);
345
+ }
346
+ return rawHMACMD5(key, string);
347
+ }
348
+
349
+ export { md5 };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * sha256 加密
3
+ * @param {string} str 字符串
4
+ * @returns {string} 返回加密后的字符串
5
+ */
6
+ export declare function sha256(str: string): string;
7
+ /**
8
+ * sha256_raw 加密
9
+ * @param {string} str 字符串
10
+ * @returns {string} 返回加密后的原始值
11
+ */
12
+ export declare function sha256Raw(str: string): any;
13
+ /**
14
+ * sha256_hmac 加密
15
+ * @param {string} str 字符串
16
+ * @param {string} key 秘钥
17
+ * @returns {string} 返回加密后的字符串
18
+ */
19
+ export declare function sha256Hmac(str: string, key: string): string;
20
+ /**
21
+ * sha256_hmac_raw 加密
22
+ * @param {string} str 字符串
23
+ * @param {string} key 秘钥
24
+ * @returns {string} 返回加密后的原始值
25
+ */
26
+ export declare function sha256HmacRaw(str: string, key: string): any;
27
+ /**
28
+ * sha224 加密
29
+ * @param {string} str 字符串
30
+ * @returns {string} 返回加密后的字符串
31
+ */
32
+ export declare function sha224(str: string): string;
33
+ /**
34
+ * sha224_raw 加密
35
+ * @param {string} str 字符串
36
+ * @returns {string} 返回加密后的原始值
37
+ */
38
+ export declare function sha224Raw(str: string): any;
39
+ /**
40
+ * sha224_hmac 加密
41
+ * @param {string} str 字符串
42
+ * @param {string} key 秘钥
43
+ * @returns {string} 返回加密后的字符串
44
+ */
45
+ export declare function sha224Hmac(str: string, key: string): string;
46
+ /**
47
+ * sha224_hmac_raw 加密
48
+ * @param {string} str 字符串
49
+ * @param {string} key 秘钥
50
+ * @returns {string} 返回加密后的原始值
51
+ */
52
+ export declare function sha224HmacRaw(str: string, key: string): any;
@@ -0,0 +1,86 @@
1
+ import { sha256 as sha256$1, sha256_raw, sha256_hmac, sha256_hmac_raw, sha224 as sha224$1, sha224_raw, sha224_hmac, sha224_hmac_raw } from './sha256.mjs';
2
+
3
+ // sha256
4
+ /**
5
+ * sha256 加密
6
+ * @param {string} str 字符串
7
+ * @returns {string} 返回加密后的字符串
8
+ */
9
+ function sha256(str) {
10
+ return sha256$1(str);
11
+ }
12
+ /**
13
+ * sha256_raw 加密
14
+ * @param {string} str 字符串
15
+ * @returns {string} 返回加密后的原始值
16
+ */
17
+ function sha256Raw(str) {
18
+ return sha256_raw(str);
19
+ }
20
+ /**
21
+ * sha256_hmac 加密
22
+ * @param {string} str 字符串
23
+ * @param {string} key 秘钥
24
+ * @returns {string} 返回加密后的字符串
25
+ */
26
+ function sha256Hmac(str, key) {
27
+ if (!str || !key) {
28
+ throw new Error("Missing str or key");
29
+ }
30
+ return sha256_hmac(key, str);
31
+ }
32
+ /**
33
+ * sha256_hmac_raw 加密
34
+ * @param {string} str 字符串
35
+ * @param {string} key 秘钥
36
+ * @returns {string} 返回加密后的原始值
37
+ */
38
+ function sha256HmacRaw(str, key) {
39
+ if (!str || !key) {
40
+ throw new Error("Missing str or key");
41
+ }
42
+ return sha256_hmac_raw(key, str);
43
+ }
44
+ // sha224
45
+ /**
46
+ * sha224 加密
47
+ * @param {string} str 字符串
48
+ * @returns {string} 返回加密后的字符串
49
+ */
50
+ function sha224(str) {
51
+ return sha224$1(str);
52
+ }
53
+ /**
54
+ * sha224_raw 加密
55
+ * @param {string} str 字符串
56
+ * @returns {string} 返回加密后的原始值
57
+ */
58
+ function sha224Raw(str) {
59
+ return sha224_raw(str);
60
+ }
61
+ /**
62
+ * sha224_hmac 加密
63
+ * @param {string} str 字符串
64
+ * @param {string} key 秘钥
65
+ * @returns {string} 返回加密后的字符串
66
+ */
67
+ function sha224Hmac(str, key) {
68
+ if (!str || !key) {
69
+ throw new Error("Missing str or key");
70
+ }
71
+ return sha224_hmac(key, str);
72
+ }
73
+ /**
74
+ * sha224_hmac_raw 加密
75
+ * @param {string} str 字符串
76
+ * @param {string} key 秘钥
77
+ * @returns {string} 返回加密后的原始值
78
+ */
79
+ function sha224HmacRaw(str, key) {
80
+ if (!str || !key) {
81
+ throw new Error("Missing str or key");
82
+ }
83
+ return sha224_hmac_raw(key, str);
84
+ }
85
+
86
+ export { sha224, sha224Hmac, sha224HmacRaw, sha224Raw, sha256, sha256Hmac, sha256HmacRaw, sha256Raw };
@@ -0,0 +1,82 @@
1
+ export function sha256(message: any): string;
2
+ export namespace sha256 {
3
+ function raw(message: any): string;
4
+ function digest(message: any): number[];
5
+ function arrayBuffer(message: any): ArrayBuffer;
6
+ function create(): Sha256;
7
+ function update(message: any): Sha256;
8
+ }
9
+ export function sha256_raw(message: any): string;
10
+ export namespace sha256_raw {
11
+ function hex(message: any): string;
12
+ function digest(message: any): number[];
13
+ function arrayBuffer(message: any): ArrayBuffer;
14
+ function create(): Sha256;
15
+ function update(message: any): Sha256;
16
+ }
17
+ export function sha256_hmac(key: any, message: any): string;
18
+ export namespace sha256_hmac {
19
+ function raw(key: any, message: any): string;
20
+ function digest(key: any, message: any): number[];
21
+ function arrayBuffer(key: any, message: any): ArrayBuffer;
22
+ function create(key: any): HmacSha256;
23
+ function update(key: any, message: any): HmacSha256;
24
+ }
25
+ export function sha256_hmac_raw(key: any, message: any): string;
26
+ export namespace sha256_hmac_raw {
27
+ function hex(key: any, message: any): string;
28
+ function digest(key: any, message: any): number[];
29
+ function arrayBuffer(key: any, message: any): ArrayBuffer;
30
+ function create(key: any): HmacSha256;
31
+ function update(key: any, message: any): HmacSha256;
32
+ }
33
+ export function sha256(message: any): string;
34
+ export namespace sha256 { }
35
+ export function sha256_raw(message: any): string;
36
+ export namespace sha256_raw { }
37
+ export function sha256_hmac(key: any, message: any): string;
38
+ export namespace sha256_hmac { }
39
+ export function sha256_hmac_raw(key: any, message: any): string;
40
+ export namespace sha256_hmac_raw { }
41
+ declare class Sha256 {
42
+ constructor(is224?: boolean);
43
+ blocks: any[];
44
+ h0: number;
45
+ h1: number;
46
+ h2: number;
47
+ h3: number;
48
+ h4: number;
49
+ h5: number;
50
+ h6: number;
51
+ h7: number;
52
+ block: number;
53
+ start: number;
54
+ bytes: number;
55
+ hBytes: number;
56
+ finalized: boolean;
57
+ hashed: boolean;
58
+ first: boolean;
59
+ is224: boolean;
60
+ update(message: any): this;
61
+ lastByteIndex: number | undefined;
62
+ hash(): void;
63
+ finalize(): this;
64
+ hex(): string;
65
+ digest(): number[];
66
+ raw(): string;
67
+ arrayBuffer(): ArrayBuffer;
68
+ }
69
+ declare class HmacSha256 {
70
+ constructor(key: any, is224?: boolean);
71
+ sha256: Sha256;
72
+ oKeyPad: number[];
73
+ is224: boolean;
74
+ inner: boolean;
75
+ update(message: any): this;
76
+ finalize(): this;
77
+ hex(): string;
78
+ digest(): number[];
79
+ raw(): string;
80
+ arrayBuffer(): ArrayBuffer;
81
+ }
82
+ export {};