@ivujs/i-utils 1.1.14 → 1.1.16

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 (213) hide show
  1. package/dist/cjs/ID-card/index.cjs +87 -0
  2. package/dist/cjs/array/index.cjs +470 -0
  3. package/dist/cjs/clipboard/index.cjs +128 -0
  4. package/dist/cjs/color/index.cjs +193 -0
  5. package/dist/cjs/constants/date.cjs +178 -0
  6. package/dist/cjs/constants/id-card.cjs +52 -0
  7. package/dist/cjs/constants/keycode.cjs +117 -0
  8. package/dist/cjs/constants/lang.cjs +13 -0
  9. package/dist/cjs/constants/math.cjs +13 -0
  10. package/dist/cjs/constants/regexp.cjs +53 -0
  11. package/dist/cjs/constants/sort.cjs +15 -0
  12. package/dist/cjs/cookie/index.cjs +70 -0
  13. package/dist/cjs/crypto/aes/aes.cjs +480 -0
  14. package/dist/cjs/crypto/aes/index.cjs +27 -0
  15. package/dist/cjs/crypto/base32/base32.cjs +357 -0
  16. package/dist/cjs/crypto/base32/index.cjs +41 -0
  17. package/dist/cjs/crypto/base64/base64.cjs +348 -0
  18. package/dist/cjs/crypto/base64/index.cjs +59 -0
  19. package/dist/cjs/crypto/des/des.cjs +257 -0
  20. package/dist/cjs/crypto/des/index.cjs +28 -0
  21. package/dist/cjs/crypto/md5/index.cjs +24 -0
  22. package/dist/cjs/crypto/md5/md5.cjs +897 -0
  23. package/dist/cjs/crypto/sha/sha1/index.cjs +24 -0
  24. package/dist/cjs/crypto/sha/sha1/sha1.cjs +529 -0
  25. package/dist/cjs/crypto/sha/sha256/index.cjs +43 -0
  26. package/dist/cjs/crypto/sha/sha256/sha256.cjs +595 -0
  27. package/dist/cjs/crypto/sha/sha3/index.cjs +41 -0
  28. package/dist/cjs/crypto/sha/sha3/sha3.cjs +624 -0
  29. package/dist/cjs/crypto/sha/sha512/index.cjs +81 -0
  30. package/dist/cjs/crypto/sha/sha512/sha512.cjs +950 -0
  31. package/dist/cjs/crypto/sm/lib/asn1.cjs +149 -0
  32. package/dist/cjs/crypto/sm/lib/ec.cjs +315 -0
  33. package/dist/cjs/crypto/sm/lib/jsbn.cjs +1608 -0
  34. package/dist/cjs/crypto/sm/lib/sm3.cjs +158 -0
  35. package/dist/cjs/crypto/sm/lib/utils.cjs +170 -0
  36. package/dist/cjs/crypto/sm/sm2/index.cjs +112 -0
  37. package/dist/cjs/crypto/sm/sm2/sm2.cjs +231 -0
  38. package/dist/cjs/crypto/sm/sm3/index.cjs +15 -0
  39. package/dist/cjs/crypto/sm/sm3/sm3.cjs +93 -0
  40. package/dist/cjs/crypto/sm/sm4/index.cjs +27 -0
  41. package/dist/cjs/crypto/sm/sm4/sm4.cjs +327 -0
  42. package/dist/cjs/crypto/tea/index.cjs +25 -0
  43. package/dist/cjs/crypto/tea/tea.cjs +187 -0
  44. package/dist/cjs/date/index.cjs +1266 -0
  45. package/dist/cjs/desensitized/index.cjs +75 -0
  46. package/dist/cjs/device/index.cjs +151 -0
  47. package/dist/cjs/dom/index.cjs +129 -0
  48. package/dist/cjs/file/index.cjs +333 -0
  49. package/dist/cjs/function/index.cjs +69 -0
  50. package/dist/cjs/id/index.cjs +1 -1
  51. package/dist/cjs/index.cjs +398 -47
  52. package/dist/cjs/keycode/index.cjs +33 -0
  53. package/dist/cjs/math/index.cjs +278 -0
  54. package/dist/cjs/number/index.cjs +31 -0
  55. package/dist/cjs/object/index.cjs +272 -0
  56. package/dist/cjs/pagination/index.cjs +131 -0
  57. package/dist/cjs/random/index.cjs +24 -0
  58. package/dist/cjs/regexp/index.cjs +100 -0
  59. package/dist/cjs/storage/index.cjs +11 -0
  60. package/dist/cjs/storage/localStorage.cjs +37 -0
  61. package/dist/cjs/storage/sessionStorage.cjs +37 -0
  62. package/dist/cjs/string/index.cjs +358 -0
  63. package/dist/cjs/url/index.cjs +258 -0
  64. package/dist/cjs/validate/index.cjs +468 -0
  65. package/dist/cjs/weapp/index.cjs +142 -0
  66. package/dist/es/ID-card/index.d.ts +31 -0
  67. package/dist/es/ID-card/index.mjs +81 -0
  68. package/dist/es/array/index.d.ts +203 -0
  69. package/dist/es/array/index.mjs +441 -0
  70. package/dist/es/clipboard/index.d.ts +29 -0
  71. package/dist/es/clipboard/index.mjs +122 -0
  72. package/dist/es/color/index.d.ts +52 -0
  73. package/dist/es/color/index.mjs +183 -0
  74. package/dist/es/constants/date.d.ts +174 -0
  75. package/dist/es/constants/date.mjs +176 -0
  76. package/dist/es/constants/id-card.d.ts +43 -0
  77. package/dist/es/constants/id-card.mjs +50 -0
  78. package/dist/es/constants/index.d.ts +7 -0
  79. package/dist/es/constants/keycode.d.ts +103 -0
  80. package/dist/es/constants/keycode.mjs +115 -0
  81. package/dist/es/constants/lang.d.ts +4 -0
  82. package/dist/es/constants/lang.mjs +11 -0
  83. package/dist/es/constants/math.d.ts +4 -0
  84. package/dist/es/constants/math.mjs +11 -0
  85. package/dist/es/constants/regexp.d.ts +24 -0
  86. package/dist/es/constants/regexp.mjs +51 -0
  87. package/dist/es/constants/sort.d.ts +5 -0
  88. package/dist/es/constants/sort.mjs +13 -0
  89. package/dist/es/cookie/index.d.ts +29 -0
  90. package/dist/es/cookie/index.mjs +64 -0
  91. package/dist/es/crypto/aes/aes.d.ts +156 -0
  92. package/dist/es/crypto/aes/aes.mjs +478 -0
  93. package/dist/es/crypto/aes/index.d.ts +16 -0
  94. package/dist/es/crypto/aes/index.mjs +24 -0
  95. package/dist/es/crypto/base32/base32.d.ts +3 -0
  96. package/dist/es/crypto/base32/base32.mjs +353 -0
  97. package/dist/es/crypto/base32/index.d.ts +24 -0
  98. package/dist/es/crypto/base32/index.mjs +36 -0
  99. package/dist/es/crypto/base64/base64.d.ts +5 -0
  100. package/dist/es/crypto/base64/base64.mjs +342 -0
  101. package/dist/es/crypto/base64/index.d.ts +36 -0
  102. package/dist/es/crypto/base64/index.mjs +52 -0
  103. package/dist/es/crypto/des/des.d.ts +52 -0
  104. package/dist/es/crypto/des/des.mjs +255 -0
  105. package/dist/es/crypto/des/index.d.ts +14 -0
  106. package/dist/es/crypto/des/index.mjs +25 -0
  107. package/dist/es/crypto/index.d.ts +8 -0
  108. package/dist/es/crypto/md5/index.d.ts +13 -0
  109. package/dist/es/crypto/md5/index.mjs +21 -0
  110. package/dist/es/crypto/md5/md5.d.ts +144 -0
  111. package/dist/es/crypto/md5/md5.mjs +894 -0
  112. package/dist/es/crypto/sha/index.d.ts +4 -0
  113. package/dist/es/crypto/sha/sha1/index.d.ts +13 -0
  114. package/dist/es/crypto/sha/sha1/index.mjs +21 -0
  115. package/dist/es/crypto/sha/sha1/sha1.d.ts +2 -0
  116. package/dist/es/crypto/sha/sha1/sha1.mjs +526 -0
  117. package/dist/es/crypto/sha/sha256/index.d.ts +26 -0
  118. package/dist/es/crypto/sha/sha256/index.mjs +38 -0
  119. package/dist/es/crypto/sha/sha256/sha256.d.ts +4 -0
  120. package/dist/es/crypto/sha/sha256/sha256.mjs +590 -0
  121. package/dist/es/crypto/sha/sha3/index.d.ts +24 -0
  122. package/dist/es/crypto/sha/sha3/index.mjs +36 -0
  123. package/dist/es/crypto/sha/sha3/sha3.d.ts +4 -0
  124. package/dist/es/crypto/sha/sha3/sha3.mjs +619 -0
  125. package/dist/es/crypto/sha/sha512/index.d.ts +52 -0
  126. package/dist/es/crypto/sha/sha512/index.mjs +72 -0
  127. package/dist/es/crypto/sha/sha512/sha512.d.ts +8 -0
  128. package/dist/es/crypto/sha/sha512/sha512.mjs +941 -0
  129. package/dist/es/crypto/sm/index.d.ts +3 -0
  130. package/dist/es/crypto/sm/lib/asn1.d.ts +12 -0
  131. package/dist/es/crypto/sm/lib/asn1.mjs +146 -0
  132. package/dist/es/crypto/sm/lib/ec.d.ts +126 -0
  133. package/dist/es/crypto/sm/lib/ec.mjs +312 -0
  134. package/dist/es/crypto/sm/lib/jsbn.d.ts +198 -0
  135. package/dist/es/crypto/sm/lib/jsbn.mjs +1605 -0
  136. package/dist/es/crypto/sm/lib/sm3.d.ts +5 -0
  137. package/dist/es/crypto/sm/lib/sm3.mjs +155 -0
  138. package/dist/es/crypto/sm/lib/utils.d.ts +53 -0
  139. package/dist/es/crypto/sm/lib/utils.mjs +158 -0
  140. package/dist/es/crypto/sm/sm2/index.d.ts +71 -0
  141. package/dist/es/crypto/sm/sm2/index.mjs +101 -0
  142. package/dist/es/crypto/sm/sm2/sm2.d.ts +34 -0
  143. package/dist/es/crypto/sm/sm2/sm2.mjs +220 -0
  144. package/dist/es/crypto/sm/sm3/index.d.ts +7 -0
  145. package/dist/es/crypto/sm/sm3/index.mjs +13 -0
  146. package/dist/es/crypto/sm/sm3/sm3.d.ts +1 -0
  147. package/dist/es/crypto/sm/sm3/sm3.mjs +91 -0
  148. package/dist/es/crypto/sm/sm4/index.d.ts +16 -0
  149. package/dist/es/crypto/sm/sm4/index.mjs +24 -0
  150. package/dist/es/crypto/sm/sm4/sm4.d.ts +2 -0
  151. package/dist/es/crypto/sm/sm4/sm4.mjs +324 -0
  152. package/dist/es/crypto/tea/index.d.ts +14 -0
  153. package/dist/es/crypto/tea/index.mjs +22 -0
  154. package/dist/es/crypto/tea/tea.d.ts +69 -0
  155. package/dist/es/crypto/tea/tea.mjs +185 -0
  156. package/dist/es/date/index.d.ts +547 -0
  157. package/dist/es/date/index.mjs +1179 -0
  158. package/dist/es/desensitized/index.d.ts +38 -0
  159. package/dist/es/desensitized/index.mjs +69 -0
  160. package/dist/es/device/index.d.ts +67 -0
  161. package/dist/es/device/index.mjs +137 -0
  162. package/dist/es/dom/index.d.ts +57 -0
  163. package/dist/es/dom/index.mjs +119 -0
  164. package/dist/es/file/index.d.ts +93 -0
  165. package/dist/es/file/index.mjs +317 -0
  166. package/dist/es/function/index.d.ts +23 -0
  167. package/dist/es/function/index.mjs +65 -0
  168. package/dist/es/id/index.mjs +1 -1
  169. package/dist/es/index.d.ts +25 -42
  170. package/dist/es/index.mjs +54 -40
  171. package/dist/es/keycode/index.d.ts +12 -0
  172. package/dist/es/keycode/index.mjs +30 -0
  173. package/dist/es/math/index.d.ts +66 -0
  174. package/dist/es/math/index.mjs +268 -0
  175. package/dist/es/number/index.d.ts +14 -0
  176. package/dist/es/number/index.mjs +28 -0
  177. package/dist/es/object/index.d.ts +83 -0
  178. package/dist/es/object/index.mjs +259 -0
  179. package/dist/es/pagination/index.d.ts +34 -0
  180. package/dist/es/pagination/index.mjs +125 -0
  181. package/dist/es/random/index.d.ts +15 -0
  182. package/dist/es/random/index.mjs +21 -0
  183. package/dist/es/regexp/index.d.ts +63 -0
  184. package/dist/es/regexp/index.mjs +89 -0
  185. package/dist/es/storage/index.d.ts +7 -0
  186. package/dist/es/storage/index.mjs +9 -0
  187. package/dist/es/storage/localStorage.d.ts +21 -0
  188. package/dist/es/storage/localStorage.mjs +32 -0
  189. package/dist/es/storage/sessionStorage.d.ts +21 -0
  190. package/dist/es/storage/sessionStorage.mjs +32 -0
  191. package/dist/es/string/index.d.ts +121 -0
  192. package/dist/es/string/index.mjs +339 -0
  193. package/dist/es/url/index.d.ts +118 -0
  194. package/dist/es/url/index.mjs +240 -0
  195. package/dist/es/validate/index.d.ts +228 -0
  196. package/dist/es/validate/index.mjs +431 -0
  197. package/dist/es/weapp/index.d.ts +57 -0
  198. package/dist/es/weapp/index.mjs +131 -0
  199. package/dist/index.d.ts +2850 -53
  200. package/dist/lib/index.full.cjs.js +14230 -67
  201. package/dist/lib/index.full.cjs.min.js +64 -2
  202. package/dist/lib/index.full.cjs.min.js.map +1 -1
  203. package/dist/lib/index.full.esm.js +13881 -63
  204. package/dist/lib/index.full.esm.min.js +59 -2
  205. package/dist/lib/index.full.esm.min.js.map +1 -1
  206. package/dist/lib/index.full.umd.js +14230 -67
  207. package/dist/lib/index.full.umd.min.js +64 -2
  208. package/dist/lib/index.full.umd.min.js.map +1 -1
  209. package/dist/resolver/auto-imports.cjs +337 -11
  210. package/dist/resolver/auto-imports.mjs +337 -11
  211. package/dist/resolver/index.cjs +1 -1
  212. package/dist/resolver/index.mjs +1 -1
  213. package/package.json +1 -1
@@ -0,0 +1,317 @@
1
+ import { isEmpty } from '../validate/index.mjs';
2
+
3
+ /* 文件信息处理 */
4
+ /**
5
+ * 格式化文件大小自动转为 B,KB,MB,GB
6
+ * @param {Number} size 文件的大小,单位byte字节
7
+ * @returns {String} 返回格式化后的字符串
8
+ */
9
+ function formatFileSize(size) {
10
+ if (isEmpty(size))
11
+ return "0B";
12
+ if (size < 1024) {
13
+ return size + "B";
14
+ }
15
+ else if (size < 1024 * 1024) {
16
+ return (size / 1024).toFixed(2) + "KB";
17
+ }
18
+ else if (size < 1024 * 1024 * 1024) {
19
+ return (size / (1024 * 1024)).toFixed(2) + "MB";
20
+ }
21
+ else {
22
+ return (size / (1024 * 1024 * 1024)).toFixed(2) + "GB";
23
+ }
24
+ }
25
+ /**
26
+ * 获得文件名称
27
+ * @param {String} fileName 文件的全名称,例如:测试图片.jpg
28
+ * @returns {String} 返回文件的名称
29
+ */
30
+ function getFileName(fileName) {
31
+ if (isEmpty(fileName))
32
+ return;
33
+ return fileName.substring(0, fileName.lastIndexOf("."));
34
+ }
35
+ /**
36
+ * 获得文件后缀名
37
+ * @param {String} value 文件地址路径或者文件全名称,例如:http://xxx.com/mytest.jpg,测试图片.jpg
38
+ * @returns {String} 返回文件后缀名
39
+ */
40
+ function getFileSuffix(value) {
41
+ if (isEmpty(value))
42
+ return;
43
+ return value.substring(value.lastIndexOf(".") + 1).toLowerCase();
44
+ }
45
+ /* 文件转换 */
46
+ /**
47
+ * file转blob
48
+ * @param {File} file file文件
49
+ * @returns {Promise} 返回Promise的blob
50
+ */
51
+ function fileToBlob(file) {
52
+ return new Promise((resolve, reject) => {
53
+ // 读取解析文件
54
+ let reader = new FileReader();
55
+ reader.readAsArrayBuffer(file);
56
+ // 加载成功
57
+ reader.onload = (e) => {
58
+ const blob = new Blob([e.target.result], { type: file.type });
59
+ resolve(blob);
60
+ };
61
+ // 加载失败
62
+ reader.onerror = function (err) {
63
+ console.error(err);
64
+ reject(err);
65
+ };
66
+ });
67
+ }
68
+ /**
69
+ * file转base64
70
+ * @param {File} file file文件
71
+ * @returns {Promise} 返回Promise的base64
72
+ */
73
+ function fileToBase64(file) {
74
+ return new Promise((resolve, reject) => {
75
+ // 读取解析文件
76
+ let reader = new FileReader();
77
+ reader.readAsDataURL(file);
78
+ // 加载成功
79
+ reader.onload = function (e) {
80
+ resolve(e.target.result);
81
+ };
82
+ // 加载失败
83
+ reader.onerror = function (err) {
84
+ console.error(err);
85
+ reject(err);
86
+ };
87
+ });
88
+ }
89
+ /**
90
+ * file转url
91
+ * @description 适用于本地上传图片并预览,需要注意 URL.revokeObjectURL(file) 内存释放
92
+ * @param {File} file file文件
93
+ * @returns {Promise} 返回Promise的url
94
+ */
95
+ function fileToUrl(file) {
96
+ return new Promise((resolve, reject) => {
97
+ try {
98
+ resolve(URL.createObjectURL(file));
99
+ }
100
+ catch (err) {
101
+ // 捕捉异常
102
+ console.error(err);
103
+ URL.revokeObjectURL(file);
104
+ reject(err);
105
+ }
106
+ });
107
+ }
108
+ /**
109
+ * url赚file
110
+ * @param {String} url url地址
111
+ * @returns {Promise} 返回Promise的file
112
+ */
113
+ function urlToFile(url) {
114
+ return new Promise(async (resolve, reject) => {
115
+ try {
116
+ let res = await window.fetch(url);
117
+ if (res.status === 200) {
118
+ let blob = await res.blob();
119
+ let file = await blobToFile(blob);
120
+ resolve(file);
121
+ }
122
+ }
123
+ catch (err) {
124
+ console.error(err);
125
+ reject(err);
126
+ }
127
+ });
128
+ }
129
+ /**
130
+ * blob转file
131
+ * @param {Blob} blob blob数据
132
+ * @param {String} fileName 文件名称,默认以时间戳命名
133
+ * @returns {Promise} 返回Promise的file
134
+ */
135
+ function blobToFile(blob, fileName = Date.now()) {
136
+ return new Promise((resolve, reject) => {
137
+ try {
138
+ const mime = blob.type;
139
+ const size = blob.size;
140
+ const fileSuffix = mime.split("/")[1];
141
+ const file = new File([blob], `${Date.now()}.${fileSuffix}`, {
142
+ type: mime,
143
+ size: size,
144
+ name: `${fileName}.${fileSuffix}`,
145
+ lastModified: Date.now(),
146
+ lastModifiedDate: new Date(),
147
+ });
148
+ resolve(file);
149
+ }
150
+ catch (err) {
151
+ // 捕捉异常
152
+ console.error(err);
153
+ reject(err);
154
+ }
155
+ });
156
+ }
157
+ /**
158
+ * blob转文本
159
+ * @param {Blob} blob blob数据
160
+ * @returns {Promise} 返回Promise的文本
161
+ */
162
+ function blobToText(blob) {
163
+ return new Promise((resolve, reject) => {
164
+ const reader = new FileReader();
165
+ reader.onload = function (event) {
166
+ resolve(event.target.result);
167
+ };
168
+ reader.onerror = function (error) {
169
+ reject(error);
170
+ };
171
+ reader.readAsText(blob);
172
+ });
173
+ }
174
+ /**
175
+ * blob转base64
176
+ * @param {Blob} blob blob数据
177
+ * @returns {Promise} 返回Promise的base64
178
+ */
179
+ function blobToBase64(blob) {
180
+ return new Promise((resolve, reject) => {
181
+ // 读取解析文件
182
+ let reader = new FileReader();
183
+ reader.readAsDataURL(blob);
184
+ // 加载成功
185
+ reader.onload = function (e) {
186
+ resolve(e.target.result);
187
+ };
188
+ // 加载失败
189
+ reader.onerror = function (err) {
190
+ console.error(err);
191
+ reject(err);
192
+ };
193
+ });
194
+ }
195
+ /**
196
+ * base64转file
197
+ * @param {String} base64 base64数据
198
+ * @param {String} fileName 文件名称,默认以时间戳命名
199
+ * @returns {Promise} 返回Promise的file
200
+ */
201
+ function base64ToFile(base64, fileName = Date.now()) {
202
+ return new Promise((resolve, reject) => {
203
+ try {
204
+ const arr = base64.split(",");
205
+ const mime = arr[0].match(/:(.*?);/)[1];
206
+ const fileSuffix = mime.split("/")[1];
207
+ const bstr = window.atob(arr[1]);
208
+ let n = bstr.length;
209
+ const u8arr = new Uint8Array(n);
210
+ while (n--) {
211
+ u8arr[n] = bstr.charCodeAt(n);
212
+ }
213
+ resolve(new File([u8arr], `${fileName}.${fileSuffix}`, { type: mime }));
214
+ }
215
+ catch (err) {
216
+ // 捕捉异常
217
+ console.error(err);
218
+ reject(err);
219
+ }
220
+ });
221
+ }
222
+ /**
223
+ * base64转成blob
224
+ * @param {String} base64 base64数据
225
+ * @returns {Promise} 返回Promise的blob
226
+ */
227
+ function base64ToBlob(base64) {
228
+ return new Promise((resolve, reject) => {
229
+ try {
230
+ const arr = base64.split(",");
231
+ const mime = arr[0].match(/:(.*?);/)[1];
232
+ const bstr = window.atob(arr[1]);
233
+ let n = bstr.length;
234
+ const u8arr = new Uint8Array(n);
235
+ while (n--) {
236
+ u8arr[n] = bstr.charCodeAt(n);
237
+ }
238
+ resolve(new Blob([u8arr], { type: mime }));
239
+ }
240
+ catch (err) {
241
+ // 捕捉异常
242
+ console.error(err);
243
+ reject(err);
244
+ }
245
+ });
246
+ }
247
+ /**
248
+ * 图片url转base64
249
+ * @param {String} imgUrl 图片url地址
250
+ * @returns {Promise} 返回Promise的base64
251
+ */
252
+ function urlToBase64(imgUrl) {
253
+ return new Promise((resolve, reject) => {
254
+ // 设置图片
255
+ const img = new Image();
256
+ img.src = imgUrl;
257
+ // 加载成功
258
+ img.onload = function () {
259
+ // 画图
260
+ const canvas = document.createElement("canvas");
261
+ const context = canvas.getContext("2d");
262
+ canvas.width = img.width;
263
+ canvas.height = img.height;
264
+ context.drawImage(img, 0, 0, img.width, img.height);
265
+ // 转为base64
266
+ const base64 = canvas.toDataURL("image/png");
267
+ resolve(base64);
268
+ };
269
+ // 加载失败
270
+ img.onerror = function (err) {
271
+ console.error(err);
272
+ reject(err);
273
+ };
274
+ });
275
+ }
276
+ /* 下载文件 */
277
+ /**
278
+ * 下载blob格式的文件
279
+ * @param {Blob} blob blob数据
280
+ * @param {String} fileName 下载的文件名,不写后缀名则默认为原文件类型
281
+ */
282
+ function downloadBlobFile(blob, fileName) {
283
+ try {
284
+ const objUrl = window.URL.createObjectURL(blob);
285
+ const link = window.document.createElement("a");
286
+ link.download = fileName;
287
+ link.href = objUrl;
288
+ link.click();
289
+ URL.revokeObjectURL(objUrl);
290
+ }
291
+ catch (error) {
292
+ console.error(error);
293
+ }
294
+ }
295
+ /**
296
+ * 通过文件url地址下载
297
+ * @param {String} fileUrl url文件地址
298
+ * @param {String} fileName 下载的文件名,不写后缀名则默认为原文件类型
299
+ */
300
+ function downloadFileUrl(fileUrl, fileName) {
301
+ try {
302
+ const link = window.document.createElement("a");
303
+ link.download = fileName;
304
+ link.href = fileUrl;
305
+ link.target = "_blank";
306
+ // 生成节点点击
307
+ window.document.body.appendChild(link);
308
+ link.click();
309
+ // 点击后移除节点
310
+ window.document.body.removeChild(link);
311
+ }
312
+ catch (error) {
313
+ console.error(error);
314
+ }
315
+ }
316
+
317
+ export { base64ToBlob, base64ToFile, blobToBase64, blobToFile, blobToText, downloadBlobFile, downloadFileUrl, fileToBase64, fileToBlob, fileToUrl, formatFileSize, getFileName, getFileSuffix, urlToBase64, urlToFile };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * 防抖函数
3
+ * @description 事件执行后,在延迟时间内如果再次执行,会清空定时器重新延迟执行,举例:用户在输入框进行输入搜索,最终是会获取到最后一次输入,节约请求资源
4
+ * @param {Function} fn 目标函数
5
+ * @param {Number} delay 延迟时间,单位毫秒,默认 1*1000 毫秒
6
+ * @param {Boolean} immediate 是否立即执行,默认true
7
+ * @returns {Function} 返回function()
8
+ */
9
+ export function debounce(fn: Function, delay?: number, immediate?: boolean): Function;
10
+ /**
11
+ * 节流函数
12
+ * @description 高频触发时,在指定时间间隔内只执行一次,举例:监听页面滚动,不会频繁触发,只会在固定时间内获取一次
13
+ * @param {Function} fn 目标函数
14
+ * @param {Number} interval 时间间隔,单位毫秒,默认1*1000毫秒
15
+ * @returns {Function} 返回function()
16
+ */
17
+ export function throttle(fn: Function, interval?: number): Function;
18
+ /**
19
+ * 睡眠延迟执行
20
+ * @description 需要配合 async/await 来达到延迟效果
21
+ * @param {Number} delay 延迟时间,单位毫秒,默认1*1000毫秒
22
+ */
23
+ export function sleep(delay?: number): Promise<any>;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * 防抖函数
3
+ * @description 事件执行后,在延迟时间内如果再次执行,会清空定时器重新延迟执行,举例:用户在输入框进行输入搜索,最终是会获取到最后一次输入,节约请求资源
4
+ * @param {Function} fn 目标函数
5
+ * @param {Number} delay 延迟时间,单位毫秒,默认 1*1000 毫秒
6
+ * @param {Boolean} immediate 是否立即执行,默认true
7
+ * @returns {Function} 返回function()
8
+ */
9
+ function debounce(fn, delay = 1 * 1000, immediate = true) {
10
+ let timer;
11
+ return function () {
12
+ const _args = arguments;
13
+ // 先关闭定时器
14
+ if (timer)
15
+ clearTimeout(timer);
16
+ // 立即执行判断
17
+ if (immediate) {
18
+ // 如果需要立即执行
19
+ // 开启新定时器防止短时间内再次触发
20
+ const canExecute = !timer;
21
+ timer = setTimeout(function () {
22
+ timer = null;
23
+ }, delay);
24
+ if (canExecute)
25
+ fn.apply(this, _args);
26
+ }
27
+ else {
28
+ // 如果不需要立即执行
29
+ // 每次触发开启新定时器即可
30
+ timer = setTimeout(function () {
31
+ fn.apply(this, _args);
32
+ }, delay);
33
+ }
34
+ };
35
+ }
36
+ /**
37
+ * 节流函数
38
+ * @description 高频触发时,在指定时间间隔内只执行一次,举例:监听页面滚动,不会频繁触发,只会在固定时间内获取一次
39
+ * @param {Function} fn 目标函数
40
+ * @param {Number} interval 时间间隔,单位毫秒,默认1*1000毫秒
41
+ * @returns {Function} 返回function()
42
+ */
43
+ function throttle(fn, interval = 1 * 1000) {
44
+ let timer;
45
+ return function () {
46
+ const _args = arguments;
47
+ // 有定时器则返回
48
+ if (timer)
49
+ return;
50
+ timer = setTimeout(() => {
51
+ timer = null;
52
+ fn.apply(this, _args);
53
+ }, interval);
54
+ };
55
+ }
56
+ /**
57
+ * 睡眠延迟执行
58
+ * @description 需要配合 async/await 来达到延迟效果
59
+ * @param {Number} delay 延迟时间,单位毫秒,默认1*1000毫秒
60
+ */
61
+ function sleep(delay = 1 * 1000) {
62
+ return new Promise((resolve) => setTimeout(resolve, delay));
63
+ }
64
+
65
+ export { debounce, sleep, throttle };
@@ -34,7 +34,7 @@ function getUUID(len = 32, radix = 16) {
34
34
  * @returns {String} 返回字符串
35
35
  */
36
36
  function getGUID() {
37
- const s4 = function () {
37
+ let s4 = function () {
38
38
  return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
39
39
  };
40
40
  return s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4();
@@ -1,44 +1,27 @@
1
1
  export declare function loadedTestUtils(): void;
2
- export type BaseStock = {
3
- name: string;
4
- code: string;
5
- };
6
- export type HighStock = BaseStock & {
7
- chgPrice: number;
8
- chgPct: number;
9
- };
10
- export declare enum StockStatus {
11
- Idle,
12
- Loading,
13
- Done
14
- }
15
- export declare const doMain: () => void;
16
- export declare class MyClass {
17
- }
18
- export interface StockQuote {
19
- name: string;
20
- code: string;
21
- chgPct: number;
22
- }
23
- export declare class Stock {
24
- name: string;
25
- code: string;
26
- constructor(name: string, code: string);
27
- getInfo(): string;
28
- }
29
- export declare const MY_CONFIG: {
30
- readonly status: "success";
31
- };
32
- export declare const getUserInfo: () => string;
33
- /**
34
- * 导出股票信息
35
- * @param name
36
- */
37
- export declare const getStockInfo: (name: string) => string;
38
- export declare class MarketQuote {
39
- name: string;
40
- code: string;
41
- constructor(name: string, code: string);
42
- getInfo(): string;
43
- }
2
+ export * from "./constants/index.js";
3
+ export * from "./string/index.js";
4
+ export * from "./number/index.js";
5
+ export * from "./array/index.js";
6
+ export * from "./object/index.js";
7
+ export * from "./function/index.js";
8
+ export * from "./date/index.js";
9
+ export * from "./math/index.js";
10
+ export * from "./regexp/index.js";
11
+ export * from "./random/index.js";
12
+ export * from "./file/index.js";
13
+ export * from "./color/index.js";
14
+ export * from "./validate/index.js";
15
+ export * from "./keycode/index.js";
44
16
  export * from "./id/index.ts";
17
+ export * from "./crypto/index.js";
18
+ export * from "./desensitized/index.js";
19
+ export * from "./ID-card/index.js";
20
+ export * from "./pagination/index.js";
21
+ export * from "./url/index.js";
22
+ export * from "./cookie/index.js";
23
+ export * from "./storage/index.js";
24
+ export * from "./dom/index.js";
25
+ export * from "./device/index.js";
26
+ export * from "./clipboard/index.js";
27
+ export * from "./weapp/index.js";
package/dist/es/index.mjs CHANGED
@@ -1,47 +1,61 @@
1
+ export { SORT } from './constants/sort.mjs';
2
+ export { MATH } from './constants/math.mjs';
3
+ export { LANG } from './constants/lang.mjs';
4
+ export { REGEXP } from './constants/regexp.mjs';
5
+ export { DATE } from './constants/date.mjs';
6
+ export { KEYCODE } from './constants/keycode.mjs';
7
+ export { ID_CARD } from './constants/id-card.mjs';
8
+ export { formatRmbChinese, formatTemplate, formatThousand, formatTitle, inString, replaceAll, toCamelCase, toKebabCase, toLowerCase, toPascalCase, toSnakeCase, toUpperCase, trim, trimAll, trimEnd, trimStart, zeroEnd, zeroStart } from './string/index.mjs';
9
+ export { parseFloat, parseInt } from './number/index.mjs';
10
+ export { arrayAvg, arrayBottom, arrayComplement, arrayCreate, arrayDifference, arrayDown, arrayEquals, arrayInsert, arrayInsertAfter, arrayInsertBefore, arrayIntersect, arrayMax, arrayMin, arrayRemove, arrayRemoveAfter, arrayRemoveBefore, arrayShuffle, arraySort, arraySortBy, arraySum, arraySwap, arrayToTree, arrayTop, arrayUnion, arrayUnique, arrayUp, inArray, treeToArray } from './array/index.mjs';
11
+ export { clone, deepClone, getValueByPath, jsonToMap, mapToJson, mapToObject, merge, objectEquals, objectToMap, parseJson, setValueByPath, stringifyJson } from './object/index.mjs';
12
+ export { debounce, sleep, throttle } from './function/index.mjs';
13
+ export { addDate, addHours, addMillisecond, addMinutes, addMonth, addQuarter, addSeconds, addWeek, addYear, formatDate, getAge, getBetweenDates, getBetweenMonths, getBetweenYears, getChineseZodiac, getDate, getDateArray, getDateObject, getDateTime, getDayOfMonth, getDayOfWeek, getDayOfYear, getDaysOfMonth, getDaysOfWeek, getDaysOfYear, getDiffDay, getDiffMonth, getDiffWeek, getDiffYear, getFirstDateOfMonth, getFirstDateOfWeek, getFirstDateOfYear, getFullDateOfMonth, getFullDateOfWeek, getFullDateOfYear, getLastDateOfMonth, getLastDateOfWeek, getLastDateOfYear, getNow, getOverTime, getPastTime, getQuarter, getTimestamp, getUnixTimestamp, getWeek, getWeekOfMonth, getWeekOfYear, getWeeksOfMonth, getWeeksOfYear, getZodiac, isAM, isAfter, isAfterTomorrow, isBefore, isBeforeYesterday, isBetween, isCommonYear, isFirstDayOfMonth, isFirstDayOfWeek, isFirstDayOfYear, isLastDayOfMonth, isLastDayOfWeek, isLastDayOfYear, isLeapYear, isPM, isSame, isSameMonth, isSameOrAfter, isSameOrBefore, isSameWeek, isSameYear, isToday, isTomorrow, isWeekend, isWorkday, isYesterday, lastMonth, lastWeek, lastYear, nextMonth, nextWeek, nextYear, parseDate, today, tomorrow, yesterday } from './date/index.mjs';
14
+ export { add, divide, gcd, modulo, multiply, scm, subtract, toDecimal, toFixed } from './math/index.mjs';
15
+ export { isChinese, isEmail, isEnglish, isExternal, isIdCard, isLowerCase, isMobile, isUpperCase, isUrl, regexpTest } from './regexp/index.mjs';
16
+ export { getRandom, getRandomDigit } from './random/index.mjs';
17
+ export { base64ToBlob, base64ToFile, blobToBase64, blobToFile, blobToText, downloadBlobFile, downloadFileUrl, fileToBase64, fileToBlob, fileToUrl, formatFileSize, getFileName, getFileSuffix, urlToBase64, urlToFile } from './file/index.mjs';
18
+ export { getDrawHex, getDrawRgb, getDrawRgba, hexToHsl, hexToRgb, hexToRgba, rgbToHex, rgbaToHex, rgbaToHsl } from './color/index.mjs';
19
+ export { deepCompare, equals, equalsIgnoreCase, isArray, isAsyncFunction, isBigInt, isBlank, isBoolean, isDate, isDecimal, isEmpty, isError, isFalse, isFunction, isFunctionString, isInteger, isJson, isMap, isNaN, isNotBlank, isNotEmpty, isNotNaN, isNotNull, isNotUndefined, isNull, isNumber, isObject, isPromise, isRegExp, isSet, isString, isSymbol, isTrue, isUndefined, isWeakMap, isWeakSet } from './validate/index.mjs';
20
+ export { getKeyCode, getKeyName } from './keycode/index.mjs';
1
21
  export { getGUID, getUUID } from './id/index.mjs';
22
+ import * as index from './crypto/base64/index.mjs';
23
+ export { index as base64 };
24
+ import * as index$1 from './crypto/base32/index.mjs';
25
+ export { index$1 as base32 };
26
+ export { md5, md5_hmac } from './crypto/md5/index.mjs';
27
+ export { sha1, sha1_hmac } from './crypto/sha/sha1/index.mjs';
28
+ export { sha224, sha224_hmac, sha256, sha256_hmac } from './crypto/sha/sha256/index.mjs';
29
+ export { sha384, sha384_hmac, sha512, sha512_224, sha512_224_hmac, sha512_256, sha512_256_hmac, sha512_hmac } from './crypto/sha/sha512/index.mjs';
30
+ export { sha3_224, sha3_256, sha3_384, sha3_512 } from './crypto/sha/sha3/index.mjs';
31
+ import * as index$5 from './crypto/sm/sm2/index.mjs';
32
+ export { index$5 as sm2 };
33
+ import * as index$6 from './crypto/sm/sm3/index.mjs';
34
+ export { index$6 as sm3 };
35
+ import * as index$7 from './crypto/sm/sm4/index.mjs';
36
+ export { index$7 as sm4 };
37
+ import * as index$2 from './crypto/aes/index.mjs';
38
+ export { index$2 as aes };
39
+ import * as index$3 from './crypto/des/index.mjs';
40
+ export { index$3 as des };
41
+ import * as index$4 from './crypto/tea/index.mjs';
42
+ export { index$4 as tea };
43
+ export { formatStartOf, formatStartOfBankCard, formatStartOfIDCard, formatStartOfMobile, formatStartOfName } from './desensitized/index.mjs';
44
+ export { getAgeByIDCard, getBirthdayByIDCard, getInfoByIDCard, getProvinceByIDCard, getSexByIDCard } from './ID-card/index.mjs';
45
+ export { getLimit, getNextPage, getPrevPage, getRainbowPager, getTotalPage } from './pagination/index.mjs';
46
+ export { appendSearchParam, appendToSearchParam, getHost, getHostName, getPort, getProtocol, getSearchParam, getSearchString, getUrlHash, getUrlPath, hasSearchParam, parseSearchParam, prependSearchParam, prependToSearchParam, removeSearchParam, setSearchParam, stringifySearchParam } from './url/index.mjs';
47
+ export { clearCookie, getCookie, isSupportCookie, removeCookie, setCookie } from './cookie/index.mjs';
48
+ export { isSupportStorage } from './storage/index.mjs';
49
+ export { addClass, addStyle, getStyle, hasClass, htmlDecode, htmlEncode, removeClass, removeStyle, replaceClass } from './dom/index.mjs';
50
+ export { getBrowserInfo, isAndroid, isIos, isIpad, isIphone, isLinux, isMac, isPc, isPhone, isQQ, isWeixin, isWindows, isWindowsPhone } from './device/index.mjs';
51
+ export { clearClipboard, getClipboard, getClipboardText, setClipboard, setClipboardText } from './clipboard/index.mjs';
52
+ export { clearStorage, clearStorageSync, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, removeStorage, removeStorageSync, setStorage, setStorageSync } from './weapp/index.mjs';
53
+ export { clearLocalStorage, getLocalStorage, removeLocalStorage, setLocalStorage } from './storage/localStorage.mjs';
54
+ export { clearSessionStorage, getSessionStorage, removeSessionStorage, setSessionStorage } from './storage/sessionStorage.mjs';
2
55
 
3
56
  // 测试加载成功方法
4
57
  function loadedTestUtils() {
5
58
  console.log("Nice, iUtils loaded successfully!");
6
59
  }
7
- // 导出股票
8
- class Stock {
9
- name;
10
- code;
11
- constructor(name, code) {
12
- this.name = name;
13
- this.code = code;
14
- this.name = name;
15
- this.code = code;
16
- }
17
- getInfo() {
18
- return `hello,${this.name}${this.code}`;
19
- }
20
- }
21
- // 导出配置
22
- const MY_CONFIG = { status: "success" };
23
- // 导出信息
24
- const getUserInfo = function () {
25
- return "获得用户信息";
26
- };
27
- /**
28
- * 导出股票信息
29
- * @param name
30
- */
31
- const getStockInfo = (name) => {
32
- return `xxxxx${name}`;
33
- };
34
- // 导出行情
35
- class MarketQuote {
36
- name;
37
- code;
38
- constructor(name, code) {
39
- this.name = name;
40
- this.code = code;
41
- }
42
- getInfo() {
43
- return `hello,${this.name}${this.code}`;
44
- }
45
- }
46
60
 
47
- export { MY_CONFIG, MarketQuote, Stock, getStockInfo, getUserInfo, loadedTestUtils };
61
+ export { loadedTestUtils };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 根据keycode获得键名
3
+ * @param {Number} keycode 键值
4
+ * @returns {String} 返回键名
5
+ */
6
+ export function getKeyName(keycode: number): string;
7
+ /**
8
+ * 根据keyname获得键值
9
+ * @param {Number} keyname
10
+ * @returns {Number} 返回键值
11
+ */
12
+ export function getKeyCode(keyname: number): number;
@@ -0,0 +1,30 @@
1
+ import { KEYCODE } from '../constants/keycode.mjs';
2
+
3
+ /**
4
+ * 根据keycode获得键名
5
+ * @param {Number} keycode 键值
6
+ * @returns {String} 返回键名
7
+ */
8
+ function getKeyName(keycode) {
9
+ if (KEYCODE[keycode]) {
10
+ return KEYCODE[keycode];
11
+ }
12
+ else {
13
+ console.log("Unknow Key Code: " + keycode);
14
+ return "";
15
+ }
16
+ }
17
+ /**
18
+ * 根据keyname获得键值
19
+ * @param {Number} keyname
20
+ * @returns {Number} 返回键值
21
+ */
22
+ function getKeyCode(keyname) {
23
+ for (let key in KEYCODE) {
24
+ if (KEYCODE[key] === keyname) {
25
+ return key;
26
+ }
27
+ }
28
+ }
29
+
30
+ export { getKeyCode, getKeyName };