@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.
- package/README.md +40 -42
- package/dist/cjs/ID-card/index.cjs +21 -13
- package/dist/cjs/array/index.cjs +40 -34
- package/dist/cjs/clipboard/index.cjs +14 -10
- package/dist/cjs/color/index.cjs +73 -59
- package/dist/cjs/cookie/index.cjs +16 -13
- package/dist/cjs/crypto/base64/base64.cjs +398 -206
- package/dist/cjs/crypto/base64/index.cjs +58 -35
- package/dist/cjs/crypto/md5/index.cjs +33 -8
- package/dist/cjs/crypto/md5/md5.cjs +298 -844
- package/dist/cjs/crypto/sha256/index.cjs +95 -0
- package/dist/cjs/crypto/sha256/sha256.cjs +557 -0
- package/dist/cjs/crypto/sm3/index.cjs +27 -0
- package/dist/cjs/crypto/sm3/sm3.cjs +200 -0
- package/dist/cjs/crypto/sm4/index.cjs +101 -0
- package/dist/cjs/crypto/sm4/sm4.cjs +498 -0
- package/dist/cjs/date/index.cjs +379 -335
- package/dist/cjs/desensitized/index.cjs +21 -18
- package/dist/cjs/device/index.cjs +33 -30
- package/dist/cjs/dom/index.cjs +26 -23
- package/dist/cjs/file/index.cjs +51 -41
- package/dist/cjs/function/index.cjs +22 -19
- package/dist/cjs/id/index.cjs +6 -2
- package/dist/cjs/index.cjs +108 -127
- package/dist/cjs/keycode/index.cjs +9 -12
- package/dist/cjs/math/index.cjs +113 -81
- package/dist/cjs/number/index.cjs +10 -7
- package/dist/cjs/object/index.cjs +77 -30
- package/dist/cjs/pagination/index.cjs +25 -10
- package/dist/cjs/random/index.cjs +8 -5
- package/dist/cjs/regexp/index.cjs +23 -20
- package/dist/cjs/storage/index.cjs +4 -1
- package/dist/cjs/storage/localStorage.cjs +5 -5
- package/dist/cjs/storage/sessionStorage.cjs +6 -6
- package/dist/cjs/string/index.cjs +66 -63
- package/dist/cjs/url/index.cjs +83 -80
- package/dist/cjs/validate/index.cjs +122 -106
- package/dist/es/ID-card/index.d.ts +19 -14
- package/dist/es/ID-card/index.mjs +22 -14
- package/dist/es/array/index.d.ts +56 -50
- package/dist/es/array/index.mjs +40 -34
- package/dist/es/clipboard/index.d.ts +10 -7
- package/dist/es/clipboard/index.mjs +14 -10
- package/dist/es/color/index.d.ts +28 -25
- package/dist/es/color/index.mjs +73 -59
- package/dist/es/constants/date.d.ts +4 -174
- package/dist/es/constants/id-card.d.ts +4 -43
- package/dist/es/constants/index.d.ts +11 -7
- package/dist/es/constants/keycode.d.ts +1 -103
- package/dist/es/constants/lang.d.ts +4 -4
- package/dist/es/constants/math.d.ts +4 -4
- package/dist/es/constants/regexp.d.ts +4 -24
- package/dist/es/constants/sort.d.ts +4 -5
- package/dist/es/cookie/index.d.ts +13 -13
- package/dist/es/cookie/index.mjs +16 -13
- package/dist/es/crypto/base64/base64.d.ts +8 -5
- package/dist/es/crypto/base64/base64.mjs +393 -204
- package/dist/es/crypto/base64/index.d.ts +41 -24
- package/dist/es/crypto/base64/index.mjs +53 -32
- package/dist/es/crypto/index.d.ts +8 -8
- package/dist/es/crypto/md5/index.d.ts +20 -7
- package/dist/es/crypto/md5/index.mjs +32 -9
- package/dist/es/crypto/md5/md5.d.ts +9 -142
- package/dist/es/crypto/md5/md5.mjs +299 -844
- package/dist/es/crypto/sha256/index.d.ts +52 -0
- package/dist/es/crypto/sha256/index.mjs +86 -0
- package/dist/es/crypto/sha256/sha256.d.ts +82 -0
- package/dist/es/crypto/sha256/sha256.mjs +548 -0
- package/dist/es/crypto/sm3/index.d.ts +13 -0
- package/dist/es/crypto/sm3/index.mjs +24 -0
- package/dist/es/crypto/sm3/sm3.d.ts +3 -0
- package/dist/es/crypto/sm3/sm3.mjs +197 -0
- package/dist/es/crypto/sm4/index.d.ts +56 -0
- package/dist/es/crypto/sm4/index.mjs +95 -0
- package/dist/es/crypto/sm4/sm4.d.ts +48 -0
- package/dist/es/crypto/sm4/sm4.mjs +490 -0
- package/dist/es/date/index.d.ts +236 -175
- package/dist/es/date/index.mjs +378 -335
- package/dist/es/desensitized/index.d.ts +26 -23
- package/dist/es/desensitized/index.mjs +21 -18
- package/dist/es/device/index.d.ts +31 -25
- package/dist/es/device/index.mjs +33 -30
- package/dist/es/dom/index.d.ts +32 -29
- package/dist/es/dom/index.mjs +26 -23
- package/dist/es/file/index.d.ts +30 -30
- package/dist/es/file/index.mjs +51 -41
- package/dist/es/function/index.d.ts +10 -7
- package/dist/es/function/index.mjs +22 -19
- package/dist/es/id/index.d.ts +3 -0
- package/dist/es/id/index.mjs +6 -2
- package/dist/es/index.d.ts +24 -25
- package/dist/es/index.mjs +6 -23
- package/dist/es/keycode/index.d.ts +6 -6
- package/dist/es/keycode/index.mjs +9 -12
- package/dist/es/math/index.d.ts +37 -37
- package/dist/es/math/index.mjs +113 -81
- package/dist/es/number/index.d.ts +7 -7
- package/dist/es/number/index.mjs +10 -7
- package/dist/es/object/index.d.ts +20 -19
- package/dist/es/object/index.mjs +77 -30
- package/dist/es/pagination/index.d.ts +39 -6
- package/dist/es/pagination/index.mjs +25 -10
- package/dist/es/random/index.d.ts +10 -7
- package/dist/es/random/index.mjs +8 -5
- package/dist/es/regexp/index.d.ts +30 -30
- package/dist/es/regexp/index.mjs +23 -20
- package/dist/es/storage/index.d.ts +10 -4
- package/dist/es/storage/index.mjs +4 -1
- package/dist/es/storage/localStorage.d.ts +9 -9
- package/dist/es/storage/localStorage.mjs +5 -5
- package/dist/es/storage/sessionStorage.d.ts +9 -9
- package/dist/es/storage/sessionStorage.mjs +6 -6
- package/dist/es/string/index.d.ts +62 -59
- package/dist/es/string/index.mjs +66 -63
- package/dist/es/url/index.d.ts +65 -65
- package/dist/es/url/index.mjs +83 -80
- package/dist/es/validate/index.d.ts +83 -80
- package/dist/es/validate/index.mjs +122 -106
- package/dist/index.d.ts +2355 -2803
- package/dist/lib/index.full.umd.js +3297 -9474
- package/dist/lib/index.full.umd.min.js +2 -64
- package/dist/lib/index.full.umd.min.js.map +1 -1
- package/dist/resolver/auto-imports.cjs +38 -31
- package/dist/resolver/auto-imports.mjs +38 -31
- package/dist/resolver/index.cjs +1 -2
- package/dist/resolver/index.d.ts +1 -1
- package/dist/resolver/index.mjs +1 -2
- package/package.json +96 -90
- package/dist/cjs/crypto/aes/aes.cjs +0 -480
- package/dist/cjs/crypto/aes/index.cjs +0 -27
- package/dist/cjs/crypto/base32/base32.cjs +0 -357
- package/dist/cjs/crypto/base32/index.cjs +0 -41
- package/dist/cjs/crypto/des/des.cjs +0 -257
- package/dist/cjs/crypto/des/index.cjs +0 -28
- package/dist/cjs/crypto/sha/sha1/index.cjs +0 -24
- package/dist/cjs/crypto/sha/sha1/sha1.cjs +0 -529
- package/dist/cjs/crypto/sha/sha256/index.cjs +0 -43
- package/dist/cjs/crypto/sha/sha256/sha256.cjs +0 -595
- package/dist/cjs/crypto/sha/sha3/index.cjs +0 -41
- package/dist/cjs/crypto/sha/sha3/sha3.cjs +0 -624
- package/dist/cjs/crypto/sha/sha512/index.cjs +0 -81
- package/dist/cjs/crypto/sha/sha512/sha512.cjs +0 -950
- package/dist/cjs/crypto/sm/lib/asn1.cjs +0 -149
- package/dist/cjs/crypto/sm/lib/ec.cjs +0 -315
- package/dist/cjs/crypto/sm/lib/jsbn.cjs +0 -1608
- package/dist/cjs/crypto/sm/lib/sm3.cjs +0 -158
- package/dist/cjs/crypto/sm/lib/utils.cjs +0 -170
- package/dist/cjs/crypto/sm/sm2/index.cjs +0 -112
- package/dist/cjs/crypto/sm/sm2/sm2.cjs +0 -231
- package/dist/cjs/crypto/sm/sm3/index.cjs +0 -15
- package/dist/cjs/crypto/sm/sm3/sm3.cjs +0 -93
- package/dist/cjs/crypto/sm/sm4/index.cjs +0 -27
- package/dist/cjs/crypto/sm/sm4/sm4.cjs +0 -327
- package/dist/cjs/crypto/tea/index.cjs +0 -25
- package/dist/cjs/crypto/tea/tea.cjs +0 -187
- package/dist/cjs/weapp/index.cjs +0 -142
- package/dist/es/crypto/aes/aes.d.ts +0 -156
- package/dist/es/crypto/aes/aes.mjs +0 -478
- package/dist/es/crypto/aes/index.d.ts +0 -16
- package/dist/es/crypto/aes/index.mjs +0 -24
- package/dist/es/crypto/base32/base32.d.ts +0 -3
- package/dist/es/crypto/base32/base32.mjs +0 -353
- package/dist/es/crypto/base32/index.d.ts +0 -24
- package/dist/es/crypto/base32/index.mjs +0 -36
- package/dist/es/crypto/des/des.d.ts +0 -52
- package/dist/es/crypto/des/des.mjs +0 -255
- package/dist/es/crypto/des/index.d.ts +0 -14
- package/dist/es/crypto/des/index.mjs +0 -25
- package/dist/es/crypto/sha/index.d.ts +0 -4
- package/dist/es/crypto/sha/sha1/index.d.ts +0 -13
- package/dist/es/crypto/sha/sha1/index.mjs +0 -21
- package/dist/es/crypto/sha/sha1/sha1.d.ts +0 -2
- package/dist/es/crypto/sha/sha1/sha1.mjs +0 -526
- package/dist/es/crypto/sha/sha256/index.d.ts +0 -26
- package/dist/es/crypto/sha/sha256/index.mjs +0 -38
- package/dist/es/crypto/sha/sha256/sha256.d.ts +0 -4
- package/dist/es/crypto/sha/sha256/sha256.mjs +0 -590
- package/dist/es/crypto/sha/sha3/index.d.ts +0 -24
- package/dist/es/crypto/sha/sha3/index.mjs +0 -36
- package/dist/es/crypto/sha/sha3/sha3.d.ts +0 -4
- package/dist/es/crypto/sha/sha3/sha3.mjs +0 -619
- package/dist/es/crypto/sha/sha512/index.d.ts +0 -52
- package/dist/es/crypto/sha/sha512/index.mjs +0 -72
- package/dist/es/crypto/sha/sha512/sha512.d.ts +0 -8
- package/dist/es/crypto/sha/sha512/sha512.mjs +0 -941
- package/dist/es/crypto/sm/index.d.ts +0 -3
- package/dist/es/crypto/sm/lib/asn1.d.ts +0 -12
- package/dist/es/crypto/sm/lib/asn1.mjs +0 -146
- package/dist/es/crypto/sm/lib/ec.d.ts +0 -126
- package/dist/es/crypto/sm/lib/ec.mjs +0 -312
- package/dist/es/crypto/sm/lib/jsbn.d.ts +0 -198
- package/dist/es/crypto/sm/lib/jsbn.mjs +0 -1605
- package/dist/es/crypto/sm/lib/sm3.d.ts +0 -5
- package/dist/es/crypto/sm/lib/sm3.mjs +0 -155
- package/dist/es/crypto/sm/lib/utils.d.ts +0 -53
- package/dist/es/crypto/sm/lib/utils.mjs +0 -158
- package/dist/es/crypto/sm/sm2/index.d.ts +0 -71
- package/dist/es/crypto/sm/sm2/index.mjs +0 -101
- package/dist/es/crypto/sm/sm2/sm2.d.ts +0 -34
- package/dist/es/crypto/sm/sm2/sm2.mjs +0 -220
- package/dist/es/crypto/sm/sm3/index.d.ts +0 -7
- package/dist/es/crypto/sm/sm3/index.mjs +0 -13
- package/dist/es/crypto/sm/sm3/sm3.d.ts +0 -1
- package/dist/es/crypto/sm/sm3/sm3.mjs +0 -91
- package/dist/es/crypto/sm/sm4/index.d.ts +0 -16
- package/dist/es/crypto/sm/sm4/index.mjs +0 -24
- package/dist/es/crypto/sm/sm4/sm4.d.ts +0 -2
- package/dist/es/crypto/sm/sm4/sm4.mjs +0 -324
- package/dist/es/crypto/tea/index.d.ts +0 -14
- package/dist/es/crypto/tea/index.mjs +0 -22
- package/dist/es/crypto/tea/tea.d.ts +0 -69
- package/dist/es/crypto/tea/tea.mjs +0 -185
- package/dist/es/weapp/index.d.ts +0 -57
- package/dist/es/weapp/index.mjs +0 -131
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 通过key从localStorage缓存中获取数据
|
|
3
|
-
* @param {
|
|
4
|
-
* @returns {
|
|
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 {
|
|
10
|
-
* @param {
|
|
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 {
|
|
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 {
|
|
5
|
-
* @returns {
|
|
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 {
|
|
13
|
-
* @param {
|
|
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 {
|
|
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 {
|
|
4
|
-
* @returns {
|
|
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 {
|
|
10
|
-
* @param {
|
|
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 {
|
|
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 {
|
|
5
|
-
* @returns {
|
|
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 {
|
|
13
|
-
* @param {
|
|
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 {
|
|
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 {
|
|
4
|
-
* @param {
|
|
5
|
-
* @returns {
|
|
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 {
|
|
11
|
-
* @returns {
|
|
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 {
|
|
17
|
-
* @returns {
|
|
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 {
|
|
23
|
-
* @returns {
|
|
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 {
|
|
29
|
-
* @returns {
|
|
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 {
|
|
35
|
-
* @param {
|
|
36
|
-
* @param {
|
|
37
|
-
* @returns {
|
|
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 {
|
|
43
|
-
* @returns {
|
|
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 {
|
|
49
|
-
* @returns {
|
|
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 {
|
|
56
|
-
* @returns {
|
|
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 {
|
|
63
|
-
* @returns {
|
|
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 {
|
|
70
|
-
* @returns {
|
|
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 {
|
|
77
|
-
* @returns {
|
|
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 {
|
|
84
|
-
* @param {
|
|
85
|
-
* @returns {
|
|
86
|
+
* @param {number|string} value 补零的数字
|
|
87
|
+
* @param {number} maxLength 补齐0后的最大长度,默认2位
|
|
88
|
+
* @returns {string} 返回补0后指定位数的字符串
|
|
86
89
|
*/
|
|
87
|
-
export function zeroStart(value:
|
|
90
|
+
export declare function zeroStart(value: string, maxLength?: number): string;
|
|
88
91
|
/**
|
|
89
92
|
* 数字后补齐0达到指定位数
|
|
90
93
|
* @description 相当于原生的 padEnd(2,'0')
|
|
91
|
-
* @param {
|
|
92
|
-
* @param {
|
|
93
|
-
* @returns {
|
|
94
|
+
* @param {number|string} value 补零的数字
|
|
95
|
+
* @param {number} maxLength 补齐0后的最大长度,默认2位
|
|
96
|
+
* @returns {string} 返回补0后指定位数的字符串
|
|
94
97
|
*/
|
|
95
|
-
export function zeroEnd(value:
|
|
98
|
+
export declare function zeroEnd(value: string, maxLength?: number): string;
|
|
96
99
|
/**
|
|
97
100
|
* 格式化为标题样式
|
|
98
|
-
* @param {
|
|
99
|
-
* @returns {
|
|
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 {
|
|
107
|
+
* @param {string} value 字符串值
|
|
105
108
|
* @param {Object} data 模版数据
|
|
106
|
-
* @returns {
|
|
109
|
+
* @returns {string} 返回格式化后的模版字符串
|
|
107
110
|
*/
|
|
108
|
-
export function formatTemplate(value: string, data:
|
|
111
|
+
export declare function formatTemplate(value: string, data: Record<any, any>): string;
|
|
109
112
|
/**
|
|
110
113
|
* 格式化千分位数字
|
|
111
114
|
* @description 支持任意数据传参,如果非数字则不会格式化,并返回原数据
|
|
112
|
-
* @param {
|
|
113
|
-
* @returns {
|
|
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 {
|
|
119
|
-
* @returns {
|
|
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;
|
package/dist/es/string/index.mjs
CHANGED
|
@@ -1,51 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module 字符串
|
|
3
|
+
*/
|
|
1
4
|
/* 字符串处理 */
|
|
2
5
|
/**
|
|
3
6
|
* 字符串中是否包含指定的元素
|
|
4
|
-
* @param {
|
|
5
|
-
* @param {
|
|
6
|
-
* @returns {
|
|
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 {
|
|
14
|
-
* @returns {
|
|
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 {
|
|
22
|
-
* @returns {
|
|
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 {
|
|
30
|
-
* @returns {
|
|
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 {
|
|
38
|
-
* @returns {
|
|
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 {
|
|
46
|
-
* @param {
|
|
47
|
-
* @param {
|
|
48
|
-
* @returns {
|
|
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 {
|
|
57
|
-
* @returns {
|
|
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 {
|
|
65
|
-
* @returns {
|
|
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 {
|
|
74
|
-
* @returns {
|
|
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 {
|
|
95
|
-
* @returns {
|
|
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
|
-
|
|
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 {
|
|
116
|
-
* @returns {
|
|
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 {
|
|
144
|
-
* @returns {
|
|
146
|
+
* @param {string} value 参数
|
|
147
|
+
* @returns {string} 返回处理后的字符串
|
|
145
148
|
*/
|
|
146
149
|
function toPascalCase(value) {
|
|
147
150
|
// 下划线
|
|
148
151
|
if (value.indexOf("_") > 0) {
|
|
149
|
-
|
|
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
|
-
|
|
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 {
|
|
175
|
-
* @param {
|
|
176
|
-
* @returns {
|
|
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 {
|
|
190
|
-
* @param {
|
|
191
|
-
* @returns {
|
|
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 {
|
|
204
|
-
* @returns {
|
|
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 {
|
|
221
|
+
* @param {string} value 字符串值
|
|
219
222
|
* @param {Object} data 模版数据
|
|
220
|
-
* @returns {
|
|
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 {
|
|
233
|
-
* @returns {
|
|
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
|
-
|
|
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 {
|
|
245
|
-
* @returns {
|
|
247
|
+
* @param {number|string} money 金额
|
|
248
|
+
* @returns {string} 返回金额大写
|
|
246
249
|
*/
|
|
247
250
|
function formatRmbChinese(money) {
|
|
248
251
|
// 汉字的数字
|
|
249
|
-
|
|
252
|
+
const cnNums = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
|
|
250
253
|
// 基本单位
|
|
251
|
-
|
|
254
|
+
const cnIntRadiance = ["", "拾", "佰", "仟"];
|
|
252
255
|
// 对应整数部分扩展单位
|
|
253
|
-
|
|
256
|
+
const cnIntUnits = ["", "万", "亿", "兆"];
|
|
254
257
|
// 对应小数部分单位
|
|
255
|
-
|
|
258
|
+
const cnDecUnits = ["角", "分", "毫", "厘"];
|
|
256
259
|
// 整数金额时后面跟的字符
|
|
257
|
-
|
|
260
|
+
const cnInteger = "整";
|
|
258
261
|
// 整型完以后的单位
|
|
259
|
-
|
|
262
|
+
const cnIntLast = "元";
|
|
260
263
|
// 最大处理的数字
|
|
261
|
-
|
|
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
|
-
|
|
300
|
+
const IntLen = integerNum.length;
|
|
298
301
|
for (let i = 0; i < IntLen; i++) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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
|
-
|
|
325
|
+
const decLen = decimalNum.length;
|
|
323
326
|
for (let i = 0; i < decLen; i++) {
|
|
324
|
-
|
|
327
|
+
const n = decimalNum.substr(i, 1);
|
|
325
328
|
if (n !== "0") {
|
|
326
329
|
chineseStr += cnNums[Number(n)] + cnDecUnits[i];
|
|
327
330
|
}
|