@ivujs/i-utils 2.0.0 → 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 (214) hide show
  1. package/README.md +40 -42
  2. package/dist/cjs/ID-card/index.cjs +21 -13
  3. package/dist/cjs/array/index.cjs +40 -34
  4. package/dist/cjs/clipboard/index.cjs +14 -10
  5. package/dist/cjs/color/index.cjs +73 -59
  6. package/dist/cjs/cookie/index.cjs +16 -13
  7. package/dist/cjs/crypto/base64/base64.cjs +398 -206
  8. package/dist/cjs/crypto/base64/index.cjs +58 -35
  9. package/dist/cjs/crypto/md5/index.cjs +33 -8
  10. package/dist/cjs/crypto/md5/md5.cjs +298 -844
  11. package/dist/cjs/crypto/sha256/index.cjs +95 -0
  12. package/dist/cjs/crypto/sha256/sha256.cjs +557 -0
  13. package/dist/cjs/crypto/sm3/index.cjs +27 -0
  14. package/dist/cjs/crypto/sm3/sm3.cjs +200 -0
  15. package/dist/cjs/crypto/sm4/index.cjs +101 -0
  16. package/dist/cjs/crypto/sm4/sm4.cjs +498 -0
  17. package/dist/cjs/date/index.cjs +379 -335
  18. package/dist/cjs/desensitized/index.cjs +21 -18
  19. package/dist/cjs/device/index.cjs +33 -30
  20. package/dist/cjs/dom/index.cjs +26 -23
  21. package/dist/cjs/file/index.cjs +51 -41
  22. package/dist/cjs/function/index.cjs +22 -19
  23. package/dist/cjs/id/index.cjs +6 -2
  24. package/dist/cjs/index.cjs +108 -127
  25. package/dist/cjs/keycode/index.cjs +9 -12
  26. package/dist/cjs/math/index.cjs +113 -81
  27. package/dist/cjs/number/index.cjs +10 -7
  28. package/dist/cjs/object/index.cjs +77 -30
  29. package/dist/cjs/pagination/index.cjs +25 -10
  30. package/dist/cjs/random/index.cjs +8 -5
  31. package/dist/cjs/regexp/index.cjs +23 -20
  32. package/dist/cjs/storage/index.cjs +4 -1
  33. package/dist/cjs/storage/localStorage.cjs +5 -5
  34. package/dist/cjs/storage/sessionStorage.cjs +6 -6
  35. package/dist/cjs/string/index.cjs +66 -63
  36. package/dist/cjs/url/index.cjs +83 -80
  37. package/dist/cjs/validate/index.cjs +122 -106
  38. package/dist/es/ID-card/index.d.ts +19 -14
  39. package/dist/es/ID-card/index.mjs +22 -14
  40. package/dist/es/array/index.d.ts +56 -50
  41. package/dist/es/array/index.mjs +40 -34
  42. package/dist/es/clipboard/index.d.ts +10 -7
  43. package/dist/es/clipboard/index.mjs +14 -10
  44. package/dist/es/color/index.d.ts +28 -25
  45. package/dist/es/color/index.mjs +73 -59
  46. package/dist/es/constants/date.d.ts +4 -174
  47. package/dist/es/constants/id-card.d.ts +4 -43
  48. package/dist/es/constants/index.d.ts +11 -7
  49. package/dist/es/constants/keycode.d.ts +1 -103
  50. package/dist/es/constants/lang.d.ts +4 -4
  51. package/dist/es/constants/math.d.ts +4 -4
  52. package/dist/es/constants/regexp.d.ts +4 -24
  53. package/dist/es/constants/sort.d.ts +4 -5
  54. package/dist/es/cookie/index.d.ts +13 -13
  55. package/dist/es/cookie/index.mjs +16 -13
  56. package/dist/es/crypto/base64/base64.d.ts +8 -5
  57. package/dist/es/crypto/base64/base64.mjs +393 -204
  58. package/dist/es/crypto/base64/index.d.ts +41 -24
  59. package/dist/es/crypto/base64/index.mjs +53 -32
  60. package/dist/es/crypto/index.d.ts +8 -8
  61. package/dist/es/crypto/md5/index.d.ts +20 -7
  62. package/dist/es/crypto/md5/index.mjs +32 -9
  63. package/dist/es/crypto/md5/md5.d.ts +9 -142
  64. package/dist/es/crypto/md5/md5.mjs +299 -844
  65. package/dist/es/crypto/sha256/index.d.ts +52 -0
  66. package/dist/es/crypto/sha256/index.mjs +86 -0
  67. package/dist/es/crypto/sha256/sha256.d.ts +82 -0
  68. package/dist/es/crypto/sha256/sha256.mjs +548 -0
  69. package/dist/es/crypto/sm3/index.d.ts +13 -0
  70. package/dist/es/crypto/sm3/index.mjs +24 -0
  71. package/dist/es/crypto/sm3/sm3.d.ts +3 -0
  72. package/dist/es/crypto/sm3/sm3.mjs +197 -0
  73. package/dist/es/crypto/sm4/index.d.ts +56 -0
  74. package/dist/es/crypto/sm4/index.mjs +95 -0
  75. package/dist/es/crypto/sm4/sm4.d.ts +48 -0
  76. package/dist/es/crypto/sm4/sm4.mjs +490 -0
  77. package/dist/es/date/index.d.ts +236 -175
  78. package/dist/es/date/index.mjs +378 -335
  79. package/dist/es/desensitized/index.d.ts +26 -23
  80. package/dist/es/desensitized/index.mjs +21 -18
  81. package/dist/es/device/index.d.ts +31 -25
  82. package/dist/es/device/index.mjs +33 -30
  83. package/dist/es/dom/index.d.ts +32 -29
  84. package/dist/es/dom/index.mjs +26 -23
  85. package/dist/es/file/index.d.ts +30 -30
  86. package/dist/es/file/index.mjs +51 -41
  87. package/dist/es/function/index.d.ts +10 -7
  88. package/dist/es/function/index.mjs +22 -19
  89. package/dist/es/id/index.d.ts +3 -0
  90. package/dist/es/id/index.mjs +6 -2
  91. package/dist/es/index.d.ts +24 -25
  92. package/dist/es/index.mjs +6 -23
  93. package/dist/es/keycode/index.d.ts +6 -6
  94. package/dist/es/keycode/index.mjs +9 -12
  95. package/dist/es/math/index.d.ts +37 -37
  96. package/dist/es/math/index.mjs +113 -81
  97. package/dist/es/number/index.d.ts +7 -7
  98. package/dist/es/number/index.mjs +10 -7
  99. package/dist/es/object/index.d.ts +20 -19
  100. package/dist/es/object/index.mjs +77 -30
  101. package/dist/es/pagination/index.d.ts +39 -6
  102. package/dist/es/pagination/index.mjs +25 -10
  103. package/dist/es/random/index.d.ts +10 -7
  104. package/dist/es/random/index.mjs +8 -5
  105. package/dist/es/regexp/index.d.ts +30 -30
  106. package/dist/es/regexp/index.mjs +23 -20
  107. package/dist/es/storage/index.d.ts +10 -4
  108. package/dist/es/storage/index.mjs +4 -1
  109. package/dist/es/storage/localStorage.d.ts +9 -9
  110. package/dist/es/storage/localStorage.mjs +5 -5
  111. package/dist/es/storage/sessionStorage.d.ts +9 -9
  112. package/dist/es/storage/sessionStorage.mjs +6 -6
  113. package/dist/es/string/index.d.ts +62 -59
  114. package/dist/es/string/index.mjs +66 -63
  115. package/dist/es/url/index.d.ts +65 -65
  116. package/dist/es/url/index.mjs +83 -80
  117. package/dist/es/validate/index.d.ts +83 -80
  118. package/dist/es/validate/index.mjs +122 -106
  119. package/dist/index.d.ts +2355 -2803
  120. package/dist/lib/index.full.umd.js +3297 -9474
  121. package/dist/lib/index.full.umd.min.js +2 -64
  122. package/dist/lib/index.full.umd.min.js.map +1 -1
  123. package/dist/resolver/auto-imports.cjs +38 -31
  124. package/dist/resolver/auto-imports.mjs +38 -31
  125. package/dist/resolver/index.cjs +1 -2
  126. package/dist/resolver/index.d.ts +1 -1
  127. package/dist/resolver/index.mjs +1 -2
  128. package/package.json +96 -90
  129. package/dist/cjs/crypto/aes/aes.cjs +0 -480
  130. package/dist/cjs/crypto/aes/index.cjs +0 -27
  131. package/dist/cjs/crypto/base32/base32.cjs +0 -357
  132. package/dist/cjs/crypto/base32/index.cjs +0 -41
  133. package/dist/cjs/crypto/des/des.cjs +0 -257
  134. package/dist/cjs/crypto/des/index.cjs +0 -28
  135. package/dist/cjs/crypto/sha/sha1/index.cjs +0 -24
  136. package/dist/cjs/crypto/sha/sha1/sha1.cjs +0 -529
  137. package/dist/cjs/crypto/sha/sha256/index.cjs +0 -43
  138. package/dist/cjs/crypto/sha/sha256/sha256.cjs +0 -595
  139. package/dist/cjs/crypto/sha/sha3/index.cjs +0 -41
  140. package/dist/cjs/crypto/sha/sha3/sha3.cjs +0 -624
  141. package/dist/cjs/crypto/sha/sha512/index.cjs +0 -81
  142. package/dist/cjs/crypto/sha/sha512/sha512.cjs +0 -950
  143. package/dist/cjs/crypto/sm/lib/asn1.cjs +0 -149
  144. package/dist/cjs/crypto/sm/lib/ec.cjs +0 -315
  145. package/dist/cjs/crypto/sm/lib/jsbn.cjs +0 -1608
  146. package/dist/cjs/crypto/sm/lib/sm3.cjs +0 -158
  147. package/dist/cjs/crypto/sm/lib/utils.cjs +0 -170
  148. package/dist/cjs/crypto/sm/sm2/index.cjs +0 -112
  149. package/dist/cjs/crypto/sm/sm2/sm2.cjs +0 -231
  150. package/dist/cjs/crypto/sm/sm3/index.cjs +0 -15
  151. package/dist/cjs/crypto/sm/sm3/sm3.cjs +0 -93
  152. package/dist/cjs/crypto/sm/sm4/index.cjs +0 -27
  153. package/dist/cjs/crypto/sm/sm4/sm4.cjs +0 -327
  154. package/dist/cjs/crypto/tea/index.cjs +0 -25
  155. package/dist/cjs/crypto/tea/tea.cjs +0 -187
  156. package/dist/cjs/weapp/index.cjs +0 -142
  157. package/dist/es/crypto/aes/aes.d.ts +0 -156
  158. package/dist/es/crypto/aes/aes.mjs +0 -478
  159. package/dist/es/crypto/aes/index.d.ts +0 -16
  160. package/dist/es/crypto/aes/index.mjs +0 -24
  161. package/dist/es/crypto/base32/base32.d.ts +0 -3
  162. package/dist/es/crypto/base32/base32.mjs +0 -353
  163. package/dist/es/crypto/base32/index.d.ts +0 -24
  164. package/dist/es/crypto/base32/index.mjs +0 -36
  165. package/dist/es/crypto/des/des.d.ts +0 -52
  166. package/dist/es/crypto/des/des.mjs +0 -255
  167. package/dist/es/crypto/des/index.d.ts +0 -14
  168. package/dist/es/crypto/des/index.mjs +0 -25
  169. package/dist/es/crypto/sha/index.d.ts +0 -4
  170. package/dist/es/crypto/sha/sha1/index.d.ts +0 -13
  171. package/dist/es/crypto/sha/sha1/index.mjs +0 -21
  172. package/dist/es/crypto/sha/sha1/sha1.d.ts +0 -2
  173. package/dist/es/crypto/sha/sha1/sha1.mjs +0 -526
  174. package/dist/es/crypto/sha/sha256/index.d.ts +0 -26
  175. package/dist/es/crypto/sha/sha256/index.mjs +0 -38
  176. package/dist/es/crypto/sha/sha256/sha256.d.ts +0 -4
  177. package/dist/es/crypto/sha/sha256/sha256.mjs +0 -590
  178. package/dist/es/crypto/sha/sha3/index.d.ts +0 -24
  179. package/dist/es/crypto/sha/sha3/index.mjs +0 -36
  180. package/dist/es/crypto/sha/sha3/sha3.d.ts +0 -4
  181. package/dist/es/crypto/sha/sha3/sha3.mjs +0 -619
  182. package/dist/es/crypto/sha/sha512/index.d.ts +0 -52
  183. package/dist/es/crypto/sha/sha512/index.mjs +0 -72
  184. package/dist/es/crypto/sha/sha512/sha512.d.ts +0 -8
  185. package/dist/es/crypto/sha/sha512/sha512.mjs +0 -941
  186. package/dist/es/crypto/sm/index.d.ts +0 -3
  187. package/dist/es/crypto/sm/lib/asn1.d.ts +0 -12
  188. package/dist/es/crypto/sm/lib/asn1.mjs +0 -146
  189. package/dist/es/crypto/sm/lib/ec.d.ts +0 -126
  190. package/dist/es/crypto/sm/lib/ec.mjs +0 -312
  191. package/dist/es/crypto/sm/lib/jsbn.d.ts +0 -198
  192. package/dist/es/crypto/sm/lib/jsbn.mjs +0 -1605
  193. package/dist/es/crypto/sm/lib/sm3.d.ts +0 -5
  194. package/dist/es/crypto/sm/lib/sm3.mjs +0 -155
  195. package/dist/es/crypto/sm/lib/utils.d.ts +0 -53
  196. package/dist/es/crypto/sm/lib/utils.mjs +0 -158
  197. package/dist/es/crypto/sm/sm2/index.d.ts +0 -71
  198. package/dist/es/crypto/sm/sm2/index.mjs +0 -101
  199. package/dist/es/crypto/sm/sm2/sm2.d.ts +0 -34
  200. package/dist/es/crypto/sm/sm2/sm2.mjs +0 -220
  201. package/dist/es/crypto/sm/sm3/index.d.ts +0 -7
  202. package/dist/es/crypto/sm/sm3/index.mjs +0 -13
  203. package/dist/es/crypto/sm/sm3/sm3.d.ts +0 -1
  204. package/dist/es/crypto/sm/sm3/sm3.mjs +0 -91
  205. package/dist/es/crypto/sm/sm4/index.d.ts +0 -16
  206. package/dist/es/crypto/sm/sm4/index.mjs +0 -24
  207. package/dist/es/crypto/sm/sm4/sm4.d.ts +0 -2
  208. package/dist/es/crypto/sm/sm4/sm4.mjs +0 -324
  209. package/dist/es/crypto/tea/index.d.ts +0 -14
  210. package/dist/es/crypto/tea/index.mjs +0 -22
  211. package/dist/es/crypto/tea/tea.d.ts +0 -69
  212. package/dist/es/crypto/tea/tea.mjs +0 -185
  213. package/dist/es/weapp/index.d.ts +0 -57
  214. package/dist/es/weapp/index.mjs +0 -131
@@ -1,21 +1,21 @@
1
1
  /**
2
2
  * 通过key从localStorage缓存中获取数据
3
- * @param {String} key key值
4
- * @returns {String} 返回数据
3
+ * @param {string} key key值
4
+ * @returns {string} 返回数据
5
5
  */
6
- export function getLocalStorage(key: string): string;
6
+ export declare function getLocalStorage(key: string): string | undefined;
7
7
  /**
8
8
  * 设置localStorage缓存数据
9
- * @param {String} key key值
10
- * @param {String} value value值
9
+ * @param {string} key key值
10
+ * @param {string} value value值
11
11
  */
12
- export function setLocalStorage(key: string, value: string): void;
12
+ export declare function setLocalStorage(key: string, value: string): void;
13
13
  /**
14
14
  * 通过key从localStorage缓存中删除数据
15
- * @param {String} key key值
15
+ * @param {string} key key值
16
16
  */
17
- export function removeLocalStorage(key: string): void;
17
+ export declare function removeLocalStorage(key: string): void;
18
18
  /**
19
19
  * 清空localStorage缓存中所有数据
20
20
  */
21
- export function clearLocalStorage(): void;
21
+ export declare function clearLocalStorage(): void;
@@ -1,23 +1,23 @@
1
1
  /* localStorage存储 */
2
2
  /**
3
3
  * 通过key从localStorage缓存中获取数据
4
- * @param {String} key key值
5
- * @returns {String} 返回数据
4
+ * @param {string} key key值
5
+ * @returns {string} 返回数据
6
6
  */
7
7
  function getLocalStorage(key) {
8
8
  return window.localStorage.getItem(key) || undefined;
9
9
  }
10
10
  /**
11
11
  * 设置localStorage缓存数据
12
- * @param {String} key key值
13
- * @param {String} value value值
12
+ * @param {string} key key值
13
+ * @param {string} value value值
14
14
  */
15
15
  function setLocalStorage(key, value) {
16
16
  window.localStorage.setItem(key, value);
17
17
  }
18
18
  /**
19
19
  * 通过key从localStorage缓存中删除数据
20
- * @param {String} key key值
20
+ * @param {string} key key值
21
21
  */
22
22
  function removeLocalStorage(key) {
23
23
  window.localStorage.removeItem(key);
@@ -1,21 +1,21 @@
1
1
  /**
2
2
  * 通过key从sessionStorage缓存中获取数据
3
- * @param {String} key key值
4
- * @returns {String} 返回数据
3
+ * @param {string} key key值
4
+ * @returns {string} 返回数据
5
5
  */
6
- export function getSessionStorage(key: string): string;
6
+ export declare function getSessionStorage(key: string): string | undefined;
7
7
  /**
8
8
  * 设置sessionStorage缓存数据
9
- * @param {String} key key值
10
- * @param {String} value value值
9
+ * @param {string} key key值
10
+ * @param {string} value value值
11
11
  */
12
- export function setSessionStorage(key: string, value: string): void;
12
+ export declare function setSessionStorage(key: string, value: string): void;
13
13
  /**
14
14
  * 通过key从sessionStorage缓存中删除数据
15
- * @param {String} key key值
15
+ * @param {string} key key值
16
16
  */
17
- export function removeSessionStorage(key: string): void;
17
+ export declare function removeSessionStorage(key: string): void;
18
18
  /**
19
19
  * 清空sessionStorage缓存中所有数据
20
20
  */
21
- export function clearSessionStorage(): void;
21
+ export declare function clearSessionStorage(): void;
@@ -1,23 +1,23 @@
1
1
  /* sessionStorage存储 */
2
2
  /**
3
3
  * 通过key从sessionStorage缓存中获取数据
4
- * @param {String} key key值
5
- * @returns {String} 返回数据
4
+ * @param {string} key key值
5
+ * @returns {string} 返回数据
6
6
  */
7
7
  function getSessionStorage(key) {
8
- return window.sessionStorage.getItem(key) || "";
8
+ return window.sessionStorage.getItem(key) || undefined;
9
9
  }
10
10
  /**
11
11
  * 设置sessionStorage缓存数据
12
- * @param {String} key key值
13
- * @param {String} value value值
12
+ * @param {string} key key值
13
+ * @param {string} value value值
14
14
  */
15
15
  function setSessionStorage(key, value) {
16
16
  window.sessionStorage.setItem(key, value);
17
17
  }
18
18
  /**
19
19
  * 通过key从sessionStorage缓存中删除数据
20
- * @param {String} key key值
20
+ * @param {string} key key值
21
21
  */
22
22
  function removeSessionStorage(key) {
23
23
  window.sessionStorage.removeItem(key);
@@ -1,121 +1,124 @@
1
+ /**
2
+ * @module 字符串
3
+ */
1
4
  /**
2
5
  * 字符串中是否包含指定的元素
3
- * @param {String} value 包含的元素
4
- * @param {String} str 查找的字符串
5
- * @returns {Boolean} 返回true和false
6
+ * @param {string} value 包含的元素
7
+ * @param {string} str 查找的字符串
8
+ * @returns {boolean} 返回true和false
6
9
  */
7
- export function inString(value: string, str: string): boolean;
10
+ export declare function inString(value: string, str: string): boolean;
8
11
  /**
9
12
  * 去除字符串前后位置空格
10
- * @param {String} value 参数
11
- * @returns {String} 返回处理后的字符串
13
+ * @param {string} value 参数
14
+ * @returns {string} 返回处理后的字符串
12
15
  */
13
- export function trim(value: string): string;
16
+ export declare function trim(value: string): string;
14
17
  /**
15
18
  * 去除字符串开始位置的空格
16
- * @param {String} value 参数
17
- * @returns {String} 返回处理后的字符串
19
+ * @param {string} value 参数
20
+ * @returns {string} 返回处理后的字符串
18
21
  */
19
- export function trimStart(value: string): string;
22
+ export declare function trimStart(value: string): string;
20
23
  /**
21
24
  * 去除字符串结束位置的空格
22
- * @param {String} value 参数
23
- * @returns {String} 返回处理后的字符串
25
+ * @param {string} value 参数
26
+ * @returns {string} 返回处理后的字符串
24
27
  */
25
- export function trimEnd(value: string): string;
28
+ export declare function trimEnd(value: string): string;
26
29
  /**
27
30
  * 去除字符串中全部的空格
28
- * @param {String} value 参数
29
- * @returns {String} 返回处理后的字符串
31
+ * @param {string} value 参数
32
+ * @returns {string} 返回处理后的字符串
30
33
  */
31
- export function trimAll(value: string): string;
34
+ export declare function trimAll(value: string): string;
32
35
  /**
33
36
  * 替换所有指定字符串为新的字符串
34
- * @param {String} value 参数
35
- * @param {String} oldSubstr 需要替换的字符串
36
- * @param {String} newSubstr 替换后的字符串
37
- * @returns {String} 返回处理后的字符串
37
+ * @param {string} value 参数
38
+ * @param {string} oldSubstr 需要替换的字符串
39
+ * @param {string} newSubstr 替换后的字符串
40
+ * @returns {string} 返回处理后的字符串
38
41
  */
39
- export function replaceAll(value: string, oldSubstr: string, newSubstr: string): string;
42
+ export declare function replaceAll(value: string, oldSubstr: string, newSubstr: string): string;
40
43
  /**
41
44
  * 字符串转大写
42
- * @param {String} value 参数
43
- * @returns {String} 返回处理后的字符串
45
+ * @param {string} value 参数
46
+ * @returns {string} 返回处理后的字符串
44
47
  */
45
- export function toUpperCase(value: string): string;
48
+ export declare function toUpperCase(value: string): string;
46
49
  /**
47
50
  * 字符串转小写
48
- * @param {String} value 参数
49
- * @returns {String} 返回处理后的字符串
51
+ * @param {string} value 参数
52
+ * @returns {string} 返回处理后的字符串
50
53
  */
51
- export function toLowerCase(value: string): string;
54
+ export declare function toLowerCase(value: string): string;
52
55
  /**
53
56
  * 转为 snake_case 下划线命名
54
57
  * @description 支持 驼峰命名,短横命名,帕斯卡命名
55
- * @param {String} value 参数
56
- * @returns {String} 返回处理后的字符串
58
+ * @param {string} value 参数
59
+ * @returns {string} 返回处理后的字符串
57
60
  */
58
- export function toSnakeCase(value: string): string;
61
+ export declare function toSnakeCase(value: string): string | undefined;
59
62
  /**
60
63
  * 转为 kebab-case 短横命名
61
64
  * @description 支持 下划线,驼峰命名,帕斯卡命名
62
- * @param {String} value 参数
63
- * @returns {String} 返回处理后的字符串
65
+ * @param {string} value 参数
66
+ * @returns {string} 返回处理后的字符串
64
67
  */
65
- export function toKebabCase(value: string): string;
68
+ export declare function toKebabCase(value: string): string | undefined;
66
69
  /**
67
70
  * 转为 camelCase 驼峰命名
68
71
  * @description 支持 下划线命名,短横命名,帕斯卡命名
69
- * @param {String} value 参数
70
- * @returns {String} 返回处理后的字符串
72
+ * @param {string} value 参数
73
+ * @returns {string} 返回处理后的字符串
71
74
  */
72
- export function toCamelCase(value: string): string;
75
+ export declare function toCamelCase(value: string): string;
73
76
  /**
74
77
  * 转为 PascalCase 帕斯卡命名
75
78
  * @description 支持 下划线命名,短横命名,驼峰命名
76
- * @param {String} value 参数
77
- * @returns {String} 返回处理后的字符串
79
+ * @param {string} value 参数
80
+ * @returns {string} 返回处理后的字符串
78
81
  */
79
- export function toPascalCase(value: string): string;
82
+ export declare function toPascalCase(value: string): string;
80
83
  /**
81
84
  * 数字前补齐0达到指定位数
82
85
  * @description 相当于原生的 padStart(2,'0')
83
- * @param {Number|String} value 补零的数字
84
- * @param {Number} maxLength 补齐0后的最大长度,默认2位
85
- * @returns {String} 返回补0后指定位数的字符串
86
+ * @param {number|string} value 补零的数字
87
+ * @param {number} maxLength 补齐0后的最大长度,默认2位
88
+ * @returns {string} 返回补0后指定位数的字符串
86
89
  */
87
- export function zeroStart(value: number | string, maxLength?: number): string;
90
+ export declare function zeroStart(value: string, maxLength?: number): string;
88
91
  /**
89
92
  * 数字后补齐0达到指定位数
90
93
  * @description 相当于原生的 padEnd(2,'0')
91
- * @param {Number|String} value 补零的数字
92
- * @param {Number} maxLength 补齐0后的最大长度,默认2位
93
- * @returns {String} 返回补0后指定位数的字符串
94
+ * @param {number|string} value 补零的数字
95
+ * @param {number} maxLength 补齐0后的最大长度,默认2位
96
+ * @returns {string} 返回补0后指定位数的字符串
94
97
  */
95
- export function zeroEnd(value: number | string, maxLength?: number): string;
98
+ export declare function zeroEnd(value: string, maxLength?: number): string;
96
99
  /**
97
100
  * 格式化为标题样式
98
- * @param {String} value 字符串值
99
- * @returns {String} 返回格式化后的标题样式
101
+ * @param {string} value 字符串值
102
+ * @returns {string} 返回格式化后的标题样式
100
103
  */
101
- export function formatTitle(value: string): string;
104
+ export declare function formatTitle(value: string): string;
102
105
  /**
103
106
  * 格式化字符串模版
104
- * @param {String} value 字符串值
107
+ * @param {string} value 字符串值
105
108
  * @param {Object} data 模版数据
106
- * @returns {String} 返回格式化后的模版字符串
109
+ * @returns {string} 返回格式化后的模版字符串
107
110
  */
108
- export function formatTemplate(value: string, data: Object): string;
111
+ export declare function formatTemplate(value: string, data: Record<any, any>): string;
109
112
  /**
110
113
  * 格式化千分位数字
111
114
  * @description 支持任意数据传参,如果非数字则不会格式化,并返回原数据
112
- * @param {Number|String} num 数字
113
- * @returns {String} 返回格式化后的千分位数字
115
+ * @param {number|string} num 数字
116
+ * @returns {string} 返回格式化后的千分位数字
114
117
  */
115
- export function formatThousand(num: number | string): string;
118
+ export declare function formatThousand(num: number | string): string;
116
119
  /**
117
120
  * 格式化人民币金额大写
118
- * @param {Number|String} money 金额
119
- * @returns {String} 返回金额大写
121
+ * @param {number|string} money 金额
122
+ * @returns {string} 返回金额大写
120
123
  */
121
- export function formatRmbChinese(money: number | string): string;
124
+ export declare function formatRmbChinese(money: number | string): string;
@@ -1,51 +1,54 @@
1
+ /**
2
+ * @module 字符串
3
+ */
1
4
  /* 字符串处理 */
2
5
  /**
3
6
  * 字符串中是否包含指定的元素
4
- * @param {String} value 包含的元素
5
- * @param {String} str 查找的字符串
6
- * @returns {Boolean} 返回true和false
7
+ * @param {string} value 包含的元素
8
+ * @param {string} str 查找的字符串
9
+ * @returns {boolean} 返回true和false
7
10
  */
8
11
  function inString(value, str) {
9
12
  return str.includes(value);
10
13
  }
11
14
  /**
12
15
  * 去除字符串前后位置空格
13
- * @param {String} value 参数
14
- * @returns {String} 返回处理后的字符串
16
+ * @param {string} value 参数
17
+ * @returns {string} 返回处理后的字符串
15
18
  */
16
19
  function trim(value) {
17
20
  return value.replace(/(^\s*)|(\s*$)/g, "");
18
21
  }
19
22
  /**
20
23
  * 去除字符串开始位置的空格
21
- * @param {String} value 参数
22
- * @returns {String} 返回处理后的字符串
24
+ * @param {string} value 参数
25
+ * @returns {string} 返回处理后的字符串
23
26
  */
24
27
  function trimStart(value) {
25
28
  return value.replace(/(^\s*)/g, "");
26
29
  }
27
30
  /**
28
31
  * 去除字符串结束位置的空格
29
- * @param {String} value 参数
30
- * @returns {String} 返回处理后的字符串
32
+ * @param {string} value 参数
33
+ * @returns {string} 返回处理后的字符串
31
34
  */
32
35
  function trimEnd(value) {
33
36
  return value.replace(/(\s*$)/g, "");
34
37
  }
35
38
  /**
36
39
  * 去除字符串中全部的空格
37
- * @param {String} value 参数
38
- * @returns {String} 返回处理后的字符串
40
+ * @param {string} value 参数
41
+ * @returns {string} 返回处理后的字符串
39
42
  */
40
43
  function trimAll(value) {
41
44
  return value.replace(/\s+/g, "");
42
45
  }
43
46
  /**
44
47
  * 替换所有指定字符串为新的字符串
45
- * @param {String} value 参数
46
- * @param {String} oldSubstr 需要替换的字符串
47
- * @param {String} newSubstr 替换后的字符串
48
- * @returns {String} 返回处理后的字符串
48
+ * @param {string} value 参数
49
+ * @param {string} oldSubstr 需要替换的字符串
50
+ * @param {string} newSubstr 替换后的字符串
51
+ * @returns {string} 返回处理后的字符串
49
52
  */
50
53
  function replaceAll(value, oldSubstr, newSubstr) {
51
54
  return value.replace(new RegExp(oldSubstr, "gm"), newSubstr);
@@ -53,25 +56,25 @@ function replaceAll(value, oldSubstr, newSubstr) {
53
56
  /* 字符串转换 */
54
57
  /**
55
58
  * 字符串转大写
56
- * @param {String} value 参数
57
- * @returns {String} 返回处理后的字符串
59
+ * @param {string} value 参数
60
+ * @returns {string} 返回处理后的字符串
58
61
  */
59
62
  function toUpperCase(value) {
60
63
  return String(value).toLocaleUpperCase();
61
64
  }
62
65
  /**
63
66
  * 字符串转小写
64
- * @param {String} value 参数
65
- * @returns {String} 返回处理后的字符串
67
+ * @param {string} value 参数
68
+ * @returns {string} 返回处理后的字符串
66
69
  */
67
70
  function toLowerCase(value) {
68
- String(value).toLocaleLowerCase();
71
+ return String(value).toLocaleLowerCase();
69
72
  }
70
73
  /**
71
74
  * 转为 snake_case 下划线命名
72
75
  * @description 支持 驼峰命名,短横命名,帕斯卡命名
73
- * @param {String} value 参数
74
- * @returns {String} 返回处理后的字符串
76
+ * @param {string} value 参数
77
+ * @returns {string} 返回处理后的字符串
75
78
  */
76
79
  function toSnakeCase(value) {
77
80
  // 驼峰
@@ -91,8 +94,8 @@ function toSnakeCase(value) {
91
94
  /**
92
95
  * 转为 kebab-case 短横命名
93
96
  * @description 支持 下划线,驼峰命名,帕斯卡命名
94
- * @param {String} value 参数
95
- * @returns {String} 返回处理后的字符串
97
+ * @param {string} value 参数
98
+ * @returns {string} 返回处理后的字符串
96
99
  */
97
100
  function toKebabCase(value) {
98
101
  // 下划线
@@ -105,15 +108,15 @@ function toKebabCase(value) {
105
108
  }
106
109
  // 帕斯卡
107
110
  if (/^[A-Z]$/.test(value.charAt(0)) && !(value.indexOf("-") > 0 || value.indexOf("_") > 0)) {
108
- let newStr = value.charAt(0).toLowerCase() + value.slice(1);
111
+ const newStr = value.charAt(0).toLowerCase() + value.slice(1);
109
112
  return newStr.replace(/([A-Z])/g, "-$1").toLowerCase();
110
113
  }
111
114
  }
112
115
  /**
113
116
  * 转为 camelCase 驼峰命名
114
117
  * @description 支持 下划线命名,短横命名,帕斯卡命名
115
- * @param {String} value 参数
116
- * @returns {String} 返回处理后的字符串
118
+ * @param {string} value 参数
119
+ * @returns {string} 返回处理后的字符串
117
120
  */
118
121
  function toCamelCase(value) {
119
122
  // 下划线
@@ -140,20 +143,20 @@ function toCamelCase(value) {
140
143
  /**
141
144
  * 转为 PascalCase 帕斯卡命名
142
145
  * @description 支持 下划线命名,短横命名,驼峰命名
143
- * @param {String} value 参数
144
- * @returns {String} 返回处理后的字符串
146
+ * @param {string} value 参数
147
+ * @returns {string} 返回处理后的字符串
145
148
  */
146
149
  function toPascalCase(value) {
147
150
  // 下划线
148
151
  if (value.indexOf("_") > 0) {
149
- let newStr = value.replace(/\_(\w)/g, function (all, letter) {
152
+ const newStr = value.replace(/\_(\w)/g, function (all, letter) {
150
153
  return letter.toUpperCase();
151
154
  });
152
155
  return newStr.charAt(0).toUpperCase() + newStr.slice(1);
153
156
  }
154
157
  // 短横
155
158
  else if (value.indexOf("-") > 0) {
156
- let newStr = value.replace(/\-(\w)/g, function (all, letter) {
159
+ const newStr = value.replace(/\-(\w)/g, function (all, letter) {
157
160
  return letter.toUpperCase();
158
161
  });
159
162
  return newStr.charAt(0).toUpperCase() + newStr.slice(1);
@@ -171,9 +174,9 @@ function toPascalCase(value) {
171
174
  /**
172
175
  * 数字前补齐0达到指定位数
173
176
  * @description 相当于原生的 padStart(2,'0')
174
- * @param {Number|String} value 补零的数字
175
- * @param {Number} maxLength 补齐0后的最大长度,默认2位
176
- * @returns {String} 返回补0后指定位数的字符串
177
+ * @param {number|string} value 补零的数字
178
+ * @param {number} maxLength 补齐0后的最大长度,默认2位
179
+ * @returns {string} 返回补0后指定位数的字符串
177
180
  */
178
181
  function zeroStart(value, maxLength = 2) {
179
182
  let len = value.toString().length;
@@ -186,9 +189,9 @@ function zeroStart(value, maxLength = 2) {
186
189
  /**
187
190
  * 数字后补齐0达到指定位数
188
191
  * @description 相当于原生的 padEnd(2,'0')
189
- * @param {Number|String} value 补零的数字
190
- * @param {Number} maxLength 补齐0后的最大长度,默认2位
191
- * @returns {String} 返回补0后指定位数的字符串
192
+ * @param {number|string} value 补零的数字
193
+ * @param {number} maxLength 补齐0后的最大长度,默认2位
194
+ * @returns {string} 返回补0后指定位数的字符串
192
195
  */
193
196
  function zeroEnd(value, maxLength = 2) {
194
197
  let len = value.toString().length;
@@ -200,8 +203,8 @@ function zeroEnd(value, maxLength = 2) {
200
203
  }
201
204
  /**
202
205
  * 格式化为标题样式
203
- * @param {String} value 字符串值
204
- * @returns {String} 返回格式化后的标题样式
206
+ * @param {string} value 字符串值
207
+ * @returns {string} 返回格式化后的标题样式
205
208
  */
206
209
  function formatTitle(value) {
207
210
  if (!value)
@@ -215,9 +218,9 @@ function formatTitle(value) {
215
218
  }
216
219
  /**
217
220
  * 格式化字符串模版
218
- * @param {String} value 字符串值
221
+ * @param {string} value 字符串值
219
222
  * @param {Object} data 模版数据
220
- * @returns {String} 返回格式化后的模版字符串
223
+ * @returns {string} 返回格式化后的模版字符串
221
224
  */
222
225
  function formatTemplate(value, data) {
223
226
  if (!value)
@@ -229,36 +232,36 @@ function formatTemplate(value, data) {
229
232
  /**
230
233
  * 格式化千分位数字
231
234
  * @description 支持任意数据传参,如果非数字则不会格式化,并返回原数据
232
- * @param {Number|String} num 数字
233
- * @returns {String} 返回格式化后的千分位数字
235
+ * @param {number|string} num 数字
236
+ * @returns {string} 返回格式化后的千分位数字
234
237
  */
235
238
  function formatThousand(num) {
236
- if (!parseFloat(num))
237
- return num;
239
+ if (!parseFloat(String(num)))
240
+ return String(num);
238
241
  num = String(num);
239
- let regex = num.indexOf(".") > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
242
+ const regex = num.indexOf(".") > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
240
243
  return num.replace(regex, "$1,");
241
244
  }
242
245
  /**
243
246
  * 格式化人民币金额大写
244
- * @param {Number|String} money 金额
245
- * @returns {String} 返回金额大写
247
+ * @param {number|string} money 金额
248
+ * @returns {string} 返回金额大写
246
249
  */
247
250
  function formatRmbChinese(money) {
248
251
  // 汉字的数字
249
- let cnNums = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
252
+ const cnNums = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
250
253
  // 基本单位
251
- let cnIntRadiance = ["", "拾", "佰", "仟"];
254
+ const cnIntRadiance = ["", "拾", "佰", "仟"];
252
255
  // 对应整数部分扩展单位
253
- let cnIntUnits = ["", "万", "亿", "兆"];
256
+ const cnIntUnits = ["", "万", "亿", "兆"];
254
257
  // 对应小数部分单位
255
- let cnDecUnits = ["角", "分", "毫", "厘"];
258
+ const cnDecUnits = ["角", "分", "毫", "厘"];
256
259
  // 整数金额时后面跟的字符
257
- let cnInteger = "整";
260
+ const cnInteger = "整";
258
261
  // 整型完以后的单位
259
- let cnIntLast = "元";
262
+ const cnIntLast = "元";
260
263
  // 最大处理的数字
261
- let maxNum = Number("999999999999999.9999");
264
+ const maxNum = Number("999999999999999.9999");
262
265
  // 金额整数部分
263
266
  let integerNum;
264
267
  // 金额小数部分
@@ -271,7 +274,7 @@ function formatRmbChinese(money) {
271
274
  // 不能用==
272
275
  return "";
273
276
  }
274
- money = parseFloat(money);
277
+ money = parseFloat(String(money));
275
278
  if (money >= maxNum) {
276
279
  // 超出最大处理数字,抛出异常
277
280
  throw new Error("Calculated number overflow!");
@@ -294,12 +297,12 @@ function formatRmbChinese(money) {
294
297
  // 获取整型部分转换
295
298
  if (parseInt(integerNum, 10) > 0) {
296
299
  let zeroCount = 0;
297
- let IntLen = integerNum.length;
300
+ const IntLen = integerNum.length;
298
301
  for (let i = 0; i < IntLen; i++) {
299
- let n = integerNum.substr(i, 1);
300
- let p = IntLen - i - 1;
301
- let q = p / 4;
302
- let m = p % 4;
302
+ const n = integerNum.substr(i, 1);
303
+ const p = IntLen - i - 1;
304
+ const q = p / 4;
305
+ const m = p % 4;
303
306
  if (n === "0") {
304
307
  zeroCount++;
305
308
  }
@@ -319,9 +322,9 @@ function formatRmbChinese(money) {
319
322
  }
320
323
  // 小数部分
321
324
  if (decimalNum !== "") {
322
- let decLen = decimalNum.length;
325
+ const decLen = decimalNum.length;
323
326
  for (let i = 0; i < decLen; i++) {
324
- let n = decimalNum.substr(i, 1);
327
+ const n = decimalNum.substr(i, 1);
325
328
  if (n !== "0") {
326
329
  chineseStr += cnNums[Number(n)] + cnDecUnits[i];
327
330
  }