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