@unikue/ts-lang-utils 1.2.13 → 1.3.1
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/constant/regex-pattern.d.ts +5 -0
- package/dist/cjs/constant/regex-pattern.js +41 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/util/RegexUtils/index.d.ts +1 -1
- package/dist/cjs/util/RegexUtils/index.js +3 -3
- package/dist/cjs/util/RegexUtils/isChineseIdCard.d.ts +1 -0
- package/dist/cjs/util/RegexUtils/{isChinaIdCard.js → isChineseIdCard.js} +9 -11
- package/dist/cjs/util/RegexUtils/isEmail.d.ts +0 -1
- package/dist/cjs/util/RegexUtils/isEmail.js +2 -4
- package/dist/cjs/util/RegexUtils/isMobile.d.ts +1 -2
- package/dist/cjs/util/RegexUtils/isMobile.js +13 -7
- package/dist/cjs/util/SensitiveUtils/index.d.ts +6 -0
- package/dist/cjs/util/SensitiveUtils/index.js +44 -0
- package/dist/cjs/util/SensitiveUtils/maskBankCard.d.ts +1 -0
- package/dist/cjs/util/SensitiveUtils/maskBankCard.js +42 -0
- package/dist/cjs/util/SensitiveUtils/maskChineseIdCard.d.ts +1 -0
- package/dist/cjs/util/SensitiveUtils/maskChineseIdCard.js +35 -0
- package/dist/cjs/util/SensitiveUtils/maskChineseMobile.d.ts +1 -0
- package/dist/cjs/util/SensitiveUtils/maskChineseMobile.js +36 -0
- package/dist/cjs/util/SensitiveUtils/maskChineseName.d.ts +2 -0
- package/dist/cjs/util/SensitiveUtils/maskChineseName.js +75 -0
- package/dist/cjs/util/SensitiveUtils/maskEmail.d.ts +1 -0
- package/dist/cjs/util/SensitiveUtils/maskEmail.js +41 -0
- package/dist/cjs/util/SensitiveUtils/maskMobile.d.ts +1 -0
- package/dist/cjs/util/SensitiveUtils/maskMobile.js +57 -0
- package/dist/esm/constant/regex-pattern.d.ts +5 -0
- package/dist/esm/constant/regex-pattern.js +5 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/util/RegexUtils/index.d.ts +1 -1
- package/dist/esm/util/RegexUtils/index.js +1 -1
- package/dist/esm/util/RegexUtils/isChineseIdCard.d.ts +1 -0
- package/dist/esm/util/RegexUtils/{isChinaIdCard.js → isChineseIdCard.js} +3 -3
- package/dist/esm/util/RegexUtils/isEmail.d.ts +0 -1
- package/dist/esm/util/RegexUtils/isEmail.js +1 -1
- package/dist/esm/util/RegexUtils/isMobile.d.ts +1 -2
- package/dist/esm/util/RegexUtils/isMobile.js +13 -5
- package/dist/esm/util/SensitiveUtils/index.d.ts +6 -0
- package/dist/esm/util/SensitiveUtils/index.js +6 -0
- package/dist/esm/util/SensitiveUtils/maskBankCard.d.ts +1 -0
- package/dist/esm/util/SensitiveUtils/maskBankCard.js +14 -0
- package/dist/esm/util/SensitiveUtils/maskChineseIdCard.d.ts +1 -0
- package/dist/esm/util/SensitiveUtils/maskChineseIdCard.js +7 -0
- package/dist/esm/util/SensitiveUtils/maskChineseMobile.d.ts +1 -0
- package/dist/esm/util/SensitiveUtils/maskChineseMobile.js +8 -0
- package/dist/esm/util/SensitiveUtils/maskChineseName.d.ts +2 -0
- package/dist/esm/util/SensitiveUtils/maskChineseName.js +12 -0
- package/dist/esm/util/SensitiveUtils/maskEmail.d.ts +1 -0
- package/dist/esm/util/SensitiveUtils/maskEmail.js +13 -0
- package/dist/esm/util/SensitiveUtils/maskMobile.d.ts +1 -0
- package/dist/esm/util/SensitiveUtils/maskMobile.js +29 -0
- package/package.json +15 -14
- package/dist/cjs/util/RegexUtils/isChinaIdCard.d.ts +0 -2
- package/dist/esm/util/RegexUtils/isChinaIdCard.d.ts +0 -2
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/constant/regex-pattern.ts
|
|
20
|
+
var regex_pattern_exports = {};
|
|
21
|
+
__export(regex_pattern_exports, {
|
|
22
|
+
BANK_CARD_REGEX: () => BANK_CARD_REGEX,
|
|
23
|
+
CHINESE_ID_CARD_REGEX: () => CHINESE_ID_CARD_REGEX,
|
|
24
|
+
CHINESE_MOBILE_REGEX: () => CHINESE_MOBILE_REGEX,
|
|
25
|
+
CHINESE_NAME_REGEX: () => CHINESE_NAME_REGEX,
|
|
26
|
+
EMAIL_REGEX: () => EMAIL_REGEX
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(regex_pattern_exports);
|
|
29
|
+
var BANK_CARD_REGEX = /^\d{12,19}$/;
|
|
30
|
+
var CHINESE_ID_CARD_REGEX = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/;
|
|
31
|
+
var CHINESE_MOBILE_REGEX = /^(?:\+?86-?)?1[3-9]\d{9}$/;
|
|
32
|
+
var CHINESE_NAME_REGEX = /^\p{Script=Han}{2,20}(?:·\p{Script=Han}{2,20})*$/u;
|
|
33
|
+
var EMAIL_REGEX = /^[^\s@]+@[A-Za-z0-9\u00A0-\uFFFF-]+(?:\.[A-Za-z0-9\u00A0-\uFFFF-]+)*\.[A-Za-z\u00A0-\uFFFF]{2,}$/;
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
BANK_CARD_REGEX,
|
|
37
|
+
CHINESE_ID_CARD_REGEX,
|
|
38
|
+
CHINESE_MOBILE_REGEX,
|
|
39
|
+
CHINESE_NAME_REGEX,
|
|
40
|
+
EMAIL_REGEX
|
|
41
|
+
});
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * as NumberUtils from './util/NumberUtils';
|
|
|
13
13
|
export * as ObjectUtils from './util/ObjectUtils';
|
|
14
14
|
export * as RandomUtils from './util/RandomUtils';
|
|
15
15
|
export * as RegexUtils from './util/RegexUtils';
|
|
16
|
+
export * as SensitiveUtils from './util/SensitiveUtils';
|
|
16
17
|
export * as StringUtils from './util/StringUtils';
|
|
17
18
|
export * as ThreadUtils from './util/ThreadUtils';
|
|
18
19
|
export * as TreeUtils from './util/TreeUtils';
|
package/dist/cjs/index.js
CHANGED
|
@@ -48,6 +48,7 @@ __export(src_exports, {
|
|
|
48
48
|
ObjectUtils: () => ObjectUtils,
|
|
49
49
|
RandomUtils: () => RandomUtils,
|
|
50
50
|
RegexUtils: () => RegexUtils,
|
|
51
|
+
SensitiveUtils: () => SensitiveUtils,
|
|
51
52
|
SessionStorage: () => SessionStorage,
|
|
52
53
|
StringUtils: () => StringUtils,
|
|
53
54
|
ThreadUtils: () => ThreadUtils,
|
|
@@ -71,6 +72,7 @@ var NumberUtils = __toESM(require("./util/NumberUtils"));
|
|
|
71
72
|
var ObjectUtils = __toESM(require("./util/ObjectUtils"));
|
|
72
73
|
var RandomUtils = __toESM(require("./util/RandomUtils"));
|
|
73
74
|
var RegexUtils = __toESM(require("./util/RegexUtils"));
|
|
75
|
+
var SensitiveUtils = __toESM(require("./util/SensitiveUtils"));
|
|
74
76
|
var StringUtils = __toESM(require("./util/StringUtils"));
|
|
75
77
|
var ThreadUtils = __toESM(require("./util/ThreadUtils"));
|
|
76
78
|
var TreeUtils = __toESM(require("./util/TreeUtils"));
|
|
@@ -101,6 +103,7 @@ var import_UnsupportedError = require("./type/UnsupportedError");
|
|
|
101
103
|
ObjectUtils,
|
|
102
104
|
RandomUtils,
|
|
103
105
|
RegexUtils,
|
|
106
|
+
SensitiveUtils,
|
|
104
107
|
SessionStorage,
|
|
105
108
|
StringUtils,
|
|
106
109
|
ThreadUtils,
|
|
@@ -7,7 +7,7 @@ export { isAlphabeticUpper } from './isAlphabeticUpper';
|
|
|
7
7
|
export { isAlphanumeric } from './isAlphanumeric';
|
|
8
8
|
export { isAlphanumericLower } from './isAlphanumericLower';
|
|
9
9
|
export { isAlphanumericUpper } from './isAlphanumericUpper';
|
|
10
|
-
export {
|
|
10
|
+
export { isChineseIdCard } from './isChineseIdCard';
|
|
11
11
|
export { isCompilable } from './isCompilable';
|
|
12
12
|
export { isEmail } from './isEmail';
|
|
13
13
|
export { isMobile } from './isMobile';
|
|
@@ -28,7 +28,7 @@ __export(RegexUtils_exports, {
|
|
|
28
28
|
isAlphanumeric: () => import_isAlphanumeric.isAlphanumeric,
|
|
29
29
|
isAlphanumericLower: () => import_isAlphanumericLower.isAlphanumericLower,
|
|
30
30
|
isAlphanumericUpper: () => import_isAlphanumericUpper.isAlphanumericUpper,
|
|
31
|
-
|
|
31
|
+
isChineseIdCard: () => import_isChineseIdCard.isChineseIdCard,
|
|
32
32
|
isCompilable: () => import_isCompilable.isCompilable,
|
|
33
33
|
isEmail: () => import_isEmail.isEmail,
|
|
34
34
|
isMobile: () => import_isMobile.isMobile,
|
|
@@ -47,7 +47,7 @@ var import_isAlphabeticUpper = require("./isAlphabeticUpper");
|
|
|
47
47
|
var import_isAlphanumeric = require("./isAlphanumeric");
|
|
48
48
|
var import_isAlphanumericLower = require("./isAlphanumericLower");
|
|
49
49
|
var import_isAlphanumericUpper = require("./isAlphanumericUpper");
|
|
50
|
-
var
|
|
50
|
+
var import_isChineseIdCard = require("./isChineseIdCard");
|
|
51
51
|
var import_isCompilable = require("./isCompilable");
|
|
52
52
|
var import_isEmail = require("./isEmail");
|
|
53
53
|
var import_isMobile = require("./isMobile");
|
|
@@ -66,7 +66,7 @@ var import_unescapePattern = require("./unescapePattern");
|
|
|
66
66
|
isAlphanumeric,
|
|
67
67
|
isAlphanumericLower,
|
|
68
68
|
isAlphanumericUpper,
|
|
69
|
-
|
|
69
|
+
isChineseIdCard,
|
|
70
70
|
isCompilable,
|
|
71
71
|
isEmail,
|
|
72
72
|
isMobile,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isChineseIdCard(text?: string | null, checksum?: boolean): boolean;
|
|
@@ -16,18 +16,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
|
|
19
|
-
// src/util/RegexUtils/
|
|
20
|
-
var
|
|
21
|
-
__export(
|
|
22
|
-
|
|
23
|
-
isChinaIdCard: () => isChinaIdCard
|
|
19
|
+
// src/util/RegexUtils/isChineseIdCard.ts
|
|
20
|
+
var isChineseIdCard_exports = {};
|
|
21
|
+
__export(isChineseIdCard_exports, {
|
|
22
|
+
isChineseIdCard: () => isChineseIdCard
|
|
24
23
|
});
|
|
25
|
-
module.exports = __toCommonJS(
|
|
26
|
-
var
|
|
24
|
+
module.exports = __toCommonJS(isChineseIdCard_exports);
|
|
25
|
+
var import_regex_pattern = require("../../constant/regex-pattern");
|
|
27
26
|
var CHECKSUM_WEIGHTS = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
|
|
28
27
|
var CHECKSUM_CODES = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"];
|
|
29
|
-
function
|
|
30
|
-
if (!text || !
|
|
28
|
+
function isChineseIdCard(text, checksum = true) {
|
|
29
|
+
if (!text || !import_regex_pattern.CHINESE_ID_CARD_REGEX.test(text)) {
|
|
31
30
|
return false;
|
|
32
31
|
}
|
|
33
32
|
const year = parseInt(text.substring(6, 10), 10);
|
|
@@ -48,6 +47,5 @@ function isChinaIdCard(text, checksum = true) {
|
|
|
48
47
|
}
|
|
49
48
|
// Annotate the CommonJS export names for ESM import in node:
|
|
50
49
|
0 && (module.exports = {
|
|
51
|
-
|
|
52
|
-
isChinaIdCard
|
|
50
|
+
isChineseIdCard
|
|
53
51
|
});
|
|
@@ -19,16 +19,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/util/RegexUtils/isEmail.ts
|
|
20
20
|
var isEmail_exports = {};
|
|
21
21
|
__export(isEmail_exports, {
|
|
22
|
-
EMAIL_REGEX: () => EMAIL_REGEX,
|
|
23
22
|
isEmail: () => isEmail
|
|
24
23
|
});
|
|
25
24
|
module.exports = __toCommonJS(isEmail_exports);
|
|
26
|
-
var
|
|
25
|
+
var import_regex_pattern = require("../../constant/regex-pattern");
|
|
27
26
|
function isEmail(text) {
|
|
28
|
-
return !!text && EMAIL_REGEX.test(text);
|
|
27
|
+
return !!text && import_regex_pattern.EMAIL_REGEX.test(text);
|
|
29
28
|
}
|
|
30
29
|
// Annotate the CommonJS export names for ESM import in node:
|
|
31
30
|
0 && (module.exports = {
|
|
32
|
-
EMAIL_REGEX,
|
|
33
31
|
isEmail
|
|
34
32
|
});
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
export declare function isMobile(text?: string | null, pattern?: string | RegExp): boolean;
|
|
1
|
+
export declare function isMobile(text?: string | null, alphaOrPattern?: string | RegExp): boolean;
|
|
@@ -19,24 +19,30 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/util/RegexUtils/isMobile.ts
|
|
20
20
|
var isMobile_exports = {};
|
|
21
21
|
__export(isMobile_exports, {
|
|
22
|
-
CHINA_MOBILE_REGEX: () => CHINA_MOBILE_REGEX,
|
|
23
22
|
isMobile: () => isMobile
|
|
24
23
|
});
|
|
25
24
|
module.exports = __toCommonJS(isMobile_exports);
|
|
25
|
+
var import_regex_pattern = require("../../constant/regex-pattern");
|
|
26
26
|
var import_compilePattern = require("./compilePattern");
|
|
27
|
-
var
|
|
28
|
-
function isMobile(text,
|
|
27
|
+
var import_libphonenumber_js = require("libphonenumber-js");
|
|
28
|
+
function isMobile(text, alphaOrPattern = import_regex_pattern.CHINESE_MOBILE_REGEX) {
|
|
29
29
|
if (!text) {
|
|
30
30
|
return false;
|
|
31
31
|
}
|
|
32
|
-
if (typeof
|
|
33
|
-
|
|
32
|
+
if (typeof alphaOrPattern === "string" && /^[A-Za-z]{2}$/i.test(alphaOrPattern)) {
|
|
33
|
+
try {
|
|
34
|
+
return (0, import_libphonenumber_js.isValidPhoneNumber)(text, alphaOrPattern.toUpperCase());
|
|
35
|
+
} catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (typeof alphaOrPattern === "string") {
|
|
40
|
+
const regex = (0, import_compilePattern.compilePattern)(alphaOrPattern);
|
|
34
41
|
return !!regex && regex.test(text);
|
|
35
42
|
}
|
|
36
|
-
return
|
|
43
|
+
return alphaOrPattern.test(text);
|
|
37
44
|
}
|
|
38
45
|
// Annotate the CommonJS export names for ESM import in node:
|
|
39
46
|
0 && (module.exports = {
|
|
40
|
-
CHINA_MOBILE_REGEX,
|
|
41
47
|
isMobile
|
|
42
48
|
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { maskBankCard } from './maskBankCard';
|
|
2
|
+
export { maskChineseIdCard } from './maskChineseIdCard';
|
|
3
|
+
export { maskChineseMobile } from './maskChineseMobile';
|
|
4
|
+
export { maskChineseName } from './maskChineseName';
|
|
5
|
+
export { maskEmail } from './maskEmail';
|
|
6
|
+
export { maskMobile } from './maskMobile';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/util/SensitiveUtils/index.ts
|
|
20
|
+
var SensitiveUtils_exports = {};
|
|
21
|
+
__export(SensitiveUtils_exports, {
|
|
22
|
+
maskBankCard: () => import_maskBankCard.maskBankCard,
|
|
23
|
+
maskChineseIdCard: () => import_maskChineseIdCard.maskChineseIdCard,
|
|
24
|
+
maskChineseMobile: () => import_maskChineseMobile.maskChineseMobile,
|
|
25
|
+
maskChineseName: () => import_maskChineseName.maskChineseName,
|
|
26
|
+
maskEmail: () => import_maskEmail.maskEmail,
|
|
27
|
+
maskMobile: () => import_maskMobile.maskMobile
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(SensitiveUtils_exports);
|
|
30
|
+
var import_maskBankCard = require("./maskBankCard");
|
|
31
|
+
var import_maskChineseIdCard = require("./maskChineseIdCard");
|
|
32
|
+
var import_maskChineseMobile = require("./maskChineseMobile");
|
|
33
|
+
var import_maskChineseName = require("./maskChineseName");
|
|
34
|
+
var import_maskEmail = require("./maskEmail");
|
|
35
|
+
var import_maskMobile = require("./maskMobile");
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
maskBankCard,
|
|
39
|
+
maskChineseIdCard,
|
|
40
|
+
maskChineseMobile,
|
|
41
|
+
maskChineseName,
|
|
42
|
+
maskEmail,
|
|
43
|
+
maskMobile
|
|
44
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function maskBankCard(text?: string | null): string | undefined;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/util/SensitiveUtils/maskBankCard.ts
|
|
20
|
+
var maskBankCard_exports = {};
|
|
21
|
+
__export(maskBankCard_exports, {
|
|
22
|
+
maskBankCard: () => maskBankCard
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(maskBankCard_exports);
|
|
25
|
+
var import_regex_pattern = require("../../constant/regex-pattern");
|
|
26
|
+
function maskBankCard(text) {
|
|
27
|
+
if (!text || !import_regex_pattern.BANK_CARD_REGEX.test(text)) {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
const groups = [];
|
|
31
|
+
let remaining = text.length - 4;
|
|
32
|
+
while (remaining > 0) {
|
|
33
|
+
const size = Math.min(4, remaining);
|
|
34
|
+
groups.push("*".repeat(size));
|
|
35
|
+
remaining -= size;
|
|
36
|
+
}
|
|
37
|
+
return groups.join(" ") + " " + text.substring(text.length - 4);
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
maskBankCard
|
|
42
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function maskChineseIdCard(text?: string | null): string | undefined;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/util/SensitiveUtils/maskChineseIdCard.ts
|
|
20
|
+
var maskChineseIdCard_exports = {};
|
|
21
|
+
__export(maskChineseIdCard_exports, {
|
|
22
|
+
maskChineseIdCard: () => maskChineseIdCard
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(maskChineseIdCard_exports);
|
|
25
|
+
var import_regex_pattern = require("../../constant/regex-pattern");
|
|
26
|
+
function maskChineseIdCard(text) {
|
|
27
|
+
if (!text || !import_regex_pattern.CHINESE_ID_CARD_REGEX.test(text)) {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
return text.substring(0, 3) + "*".repeat(text.length - 7) + text.substring(text.length - 4);
|
|
31
|
+
}
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
maskChineseIdCard
|
|
35
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function maskChineseMobile(text?: string | null): string | undefined;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/util/SensitiveUtils/maskChineseMobile.ts
|
|
20
|
+
var maskChineseMobile_exports = {};
|
|
21
|
+
__export(maskChineseMobile_exports, {
|
|
22
|
+
maskChineseMobile: () => maskChineseMobile
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(maskChineseMobile_exports);
|
|
25
|
+
var import_regex_pattern = require("../../constant/regex-pattern");
|
|
26
|
+
function maskChineseMobile(text) {
|
|
27
|
+
if (!text || !import_regex_pattern.CHINESE_MOBILE_REGEX.test(text)) {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
const offset = text.length - 11;
|
|
31
|
+
return text.substring(0, offset + 3) + "****" + text.substring(offset + 7);
|
|
32
|
+
}
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
maskChineseMobile
|
|
36
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/util/SensitiveUtils/maskChineseName.ts
|
|
20
|
+
var maskChineseName_exports = {};
|
|
21
|
+
__export(maskChineseName_exports, {
|
|
22
|
+
CHINESE_COMPOUND_SURNAMES: () => CHINESE_COMPOUND_SURNAMES,
|
|
23
|
+
maskChineseName: () => maskChineseName
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(maskChineseName_exports);
|
|
26
|
+
var import_regex_pattern = require("../../constant/regex-pattern");
|
|
27
|
+
var CHINESE_COMPOUND_SURNAMES = [
|
|
28
|
+
"欧阳",
|
|
29
|
+
"上官",
|
|
30
|
+
"司马",
|
|
31
|
+
"诸葛",
|
|
32
|
+
"东方",
|
|
33
|
+
"慕容",
|
|
34
|
+
"尉迟",
|
|
35
|
+
"公孙",
|
|
36
|
+
"夏侯",
|
|
37
|
+
"长孙",
|
|
38
|
+
"宇文",
|
|
39
|
+
"司徒",
|
|
40
|
+
"端木",
|
|
41
|
+
"南宫",
|
|
42
|
+
"皇甫",
|
|
43
|
+
"令狐",
|
|
44
|
+
"轩辕",
|
|
45
|
+
"太史",
|
|
46
|
+
"万俟",
|
|
47
|
+
"闻人",
|
|
48
|
+
"申屠",
|
|
49
|
+
"宗政",
|
|
50
|
+
"濮阳",
|
|
51
|
+
"公冶",
|
|
52
|
+
"太叔",
|
|
53
|
+
"公羊",
|
|
54
|
+
"赫连",
|
|
55
|
+
"澹台",
|
|
56
|
+
"拓跋",
|
|
57
|
+
"呼延",
|
|
58
|
+
"淳于",
|
|
59
|
+
"单于"
|
|
60
|
+
];
|
|
61
|
+
function maskChineseName(text) {
|
|
62
|
+
if (!text || !import_regex_pattern.CHINESE_NAME_REGEX.test(text)) {
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
return text.split("·").map((segment, index) => {
|
|
66
|
+
const chars = Array.from(segment);
|
|
67
|
+
const keepLength = index === 0 && chars.length > 2 && CHINESE_COMPOUND_SURNAMES.includes(chars.slice(0, 2).join("")) ? 2 : 1;
|
|
68
|
+
return chars.slice(0, keepLength).join("") + "*".repeat(chars.length - keepLength);
|
|
69
|
+
}).join("·");
|
|
70
|
+
}
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
CHINESE_COMPOUND_SURNAMES,
|
|
74
|
+
maskChineseName
|
|
75
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function maskEmail(text?: string | null): string | undefined;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/util/SensitiveUtils/maskEmail.ts
|
|
20
|
+
var maskEmail_exports = {};
|
|
21
|
+
__export(maskEmail_exports, {
|
|
22
|
+
maskEmail: () => maskEmail
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(maskEmail_exports);
|
|
25
|
+
var import_regex_pattern = require("../../constant/regex-pattern");
|
|
26
|
+
function maskEmail(text) {
|
|
27
|
+
if (!text || !import_regex_pattern.EMAIL_REGEX.test(text)) {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
const atIndex = text.indexOf("@");
|
|
31
|
+
const domain = text.substring(atIndex);
|
|
32
|
+
const localPart = text.substring(0, atIndex);
|
|
33
|
+
if (localPart.length <= 1) {
|
|
34
|
+
return "*" + domain;
|
|
35
|
+
}
|
|
36
|
+
return localPart.charAt(0) + "*".repeat(localPart.length - 1) + domain;
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
maskEmail
|
|
41
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function maskMobile(text?: string | null, alphaOrDial?: string): string | undefined;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/util/SensitiveUtils/maskMobile.ts
|
|
20
|
+
var maskMobile_exports = {};
|
|
21
|
+
__export(maskMobile_exports, {
|
|
22
|
+
maskMobile: () => maskMobile
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(maskMobile_exports);
|
|
25
|
+
var import_libphonenumber_js = require("libphonenumber-js");
|
|
26
|
+
function maskMobile(text, alphaOrDial) {
|
|
27
|
+
if (!text) {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
let country;
|
|
31
|
+
let input = text;
|
|
32
|
+
if (alphaOrDial) {
|
|
33
|
+
if (/^[A-Za-z]{2}$/i.test(alphaOrDial)) {
|
|
34
|
+
country = alphaOrDial.toUpperCase();
|
|
35
|
+
} else if (!text.startsWith("+")) {
|
|
36
|
+
input = "+" + alphaOrDial.replace(/^\+/, "") + text;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
let parsed;
|
|
40
|
+
try {
|
|
41
|
+
parsed = country ? (0, import_libphonenumber_js.parsePhoneNumberFromString)(input, country) : (0, import_libphonenumber_js.parsePhoneNumberFromString)(input);
|
|
42
|
+
} catch {
|
|
43
|
+
return void 0;
|
|
44
|
+
}
|
|
45
|
+
if (!parsed || !parsed.country) {
|
|
46
|
+
return void 0;
|
|
47
|
+
}
|
|
48
|
+
const phone = parsed.nationalNumber;
|
|
49
|
+
if (phone.length < 8) {
|
|
50
|
+
return void 0;
|
|
51
|
+
}
|
|
52
|
+
return phone.slice(0, phone.length - 8) + "****" + phone.slice(phone.length - 4);
|
|
53
|
+
}
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
maskMobile
|
|
57
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export var BANK_CARD_REGEX = /^\d{12,19}$/;
|
|
2
|
+
export var CHINESE_ID_CARD_REGEX = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/;
|
|
3
|
+
export var CHINESE_MOBILE_REGEX = /^(?:\+?86-?)?1[3-9]\d{9}$/;
|
|
4
|
+
export var CHINESE_NAME_REGEX = /^(?:[\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u3005\u3007\u3021-\u3029\u3038-\u303B\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFA6D\uFA70-\uFAD9]|\uD81B[\uDFE2\uDFE3\uDFF0\uDFF1]|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0\uDFF0-\uDFFF]|\uD87B[\uDC00-\uDE5D]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF]){2,20}(?:\xB7(?:[\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u3005\u3007\u3021-\u3029\u3038-\u303B\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFA6D\uFA70-\uFAD9]|\uD81B[\uDFE2\uDFE3\uDFF0\uDFF1]|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0\uDFF0-\uDFFF]|\uD87B[\uDC00-\uDE5D]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF]){2,20})*$/;
|
|
5
|
+
export var EMAIL_REGEX = /^[^\s@]+@[A-Za-z0-9\u00A0-\uFFFF-]+(?:\.[A-Za-z0-9\u00A0-\uFFFF-]+)*\.[A-Za-z\u00A0-\uFFFF]{2,}$/;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * as NumberUtils from './util/NumberUtils';
|
|
|
13
13
|
export * as ObjectUtils from './util/ObjectUtils';
|
|
14
14
|
export * as RandomUtils from './util/RandomUtils';
|
|
15
15
|
export * as RegexUtils from './util/RegexUtils';
|
|
16
|
+
export * as SensitiveUtils from './util/SensitiveUtils';
|
|
16
17
|
export * as StringUtils from './util/StringUtils';
|
|
17
18
|
export * as ThreadUtils from './util/ThreadUtils';
|
|
18
19
|
export * as TreeUtils from './util/TreeUtils';
|
package/dist/esm/index.js
CHANGED
|
@@ -28,6 +28,8 @@ import * as _RandomUtils from "./util/RandomUtils";
|
|
|
28
28
|
export { _RandomUtils as RandomUtils };
|
|
29
29
|
import * as _RegexUtils from "./util/RegexUtils";
|
|
30
30
|
export { _RegexUtils as RegexUtils };
|
|
31
|
+
import * as _SensitiveUtils from "./util/SensitiveUtils";
|
|
32
|
+
export { _SensitiveUtils as SensitiveUtils };
|
|
31
33
|
import * as _StringUtils from "./util/StringUtils";
|
|
32
34
|
export { _StringUtils as StringUtils };
|
|
33
35
|
import * as _ThreadUtils from "./util/ThreadUtils";
|
|
@@ -7,7 +7,7 @@ export { isAlphabeticUpper } from './isAlphabeticUpper';
|
|
|
7
7
|
export { isAlphanumeric } from './isAlphanumeric';
|
|
8
8
|
export { isAlphanumericLower } from './isAlphanumericLower';
|
|
9
9
|
export { isAlphanumericUpper } from './isAlphanumericUpper';
|
|
10
|
-
export {
|
|
10
|
+
export { isChineseIdCard } from './isChineseIdCard';
|
|
11
11
|
export { isCompilable } from './isCompilable';
|
|
12
12
|
export { isEmail } from './isEmail';
|
|
13
13
|
export { isMobile } from './isMobile';
|
|
@@ -7,7 +7,7 @@ export { isAlphabeticUpper } from "./isAlphabeticUpper";
|
|
|
7
7
|
export { isAlphanumeric } from "./isAlphanumeric";
|
|
8
8
|
export { isAlphanumericLower } from "./isAlphanumericLower";
|
|
9
9
|
export { isAlphanumericUpper } from "./isAlphanumericUpper";
|
|
10
|
-
export {
|
|
10
|
+
export { isChineseIdCard } from "./isChineseIdCard";
|
|
11
11
|
export { isCompilable } from "./isCompilable";
|
|
12
12
|
export { isEmail } from "./isEmail";
|
|
13
13
|
export { isMobile } from "./isMobile";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isChineseIdCard(text?: string | null, checksum?: boolean): boolean;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { CHINESE_ID_CARD_REGEX } from "../../constant/regex-pattern";
|
|
2
2
|
var CHECKSUM_WEIGHTS = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
|
|
3
3
|
var CHECKSUM_CODES = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
|
|
4
|
-
export function
|
|
4
|
+
export function isChineseIdCard(text) {
|
|
5
5
|
var checksum = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
6
|
-
if (!text || !
|
|
6
|
+
if (!text || !CHINESE_ID_CARD_REGEX.test(text)) {
|
|
7
7
|
return false;
|
|
8
8
|
}
|
|
9
9
|
var year = parseInt(text.substring(6, 10), 10);
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
export declare function isMobile(text?: string | null, pattern?: string | RegExp): boolean;
|
|
1
|
+
export declare function isMobile(text?: string | null, alphaOrPattern?: string | RegExp): boolean;
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
+
import { CHINESE_MOBILE_REGEX } from "../../constant/regex-pattern";
|
|
1
2
|
import { compilePattern } from "./compilePattern";
|
|
2
|
-
|
|
3
|
+
import { isValidPhoneNumber } from 'libphonenumber-js';
|
|
3
4
|
export function isMobile(text) {
|
|
4
|
-
var
|
|
5
|
+
var alphaOrPattern = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : CHINESE_MOBILE_REGEX;
|
|
5
6
|
if (!text) {
|
|
6
7
|
return false;
|
|
7
8
|
}
|
|
8
|
-
if (typeof
|
|
9
|
-
|
|
9
|
+
if (typeof alphaOrPattern === 'string' && /^[A-Za-z]{2}$/i.test(alphaOrPattern)) {
|
|
10
|
+
try {
|
|
11
|
+
return isValidPhoneNumber(text, alphaOrPattern.toUpperCase());
|
|
12
|
+
} catch (_unused) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (typeof alphaOrPattern === 'string') {
|
|
17
|
+
var regex = compilePattern(alphaOrPattern);
|
|
10
18
|
return !!regex && regex.test(text);
|
|
11
19
|
}
|
|
12
|
-
return
|
|
20
|
+
return alphaOrPattern.test(text);
|
|
13
21
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { maskBankCard } from './maskBankCard';
|
|
2
|
+
export { maskChineseIdCard } from './maskChineseIdCard';
|
|
3
|
+
export { maskChineseMobile } from './maskChineseMobile';
|
|
4
|
+
export { maskChineseName } from './maskChineseName';
|
|
5
|
+
export { maskEmail } from './maskEmail';
|
|
6
|
+
export { maskMobile } from './maskMobile';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { maskBankCard } from "./maskBankCard";
|
|
2
|
+
export { maskChineseIdCard } from "./maskChineseIdCard";
|
|
3
|
+
export { maskChineseMobile } from "./maskChineseMobile";
|
|
4
|
+
export { maskChineseName } from "./maskChineseName";
|
|
5
|
+
export { maskEmail } from "./maskEmail";
|
|
6
|
+
export { maskMobile } from "./maskMobile";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function maskBankCard(text?: string | null): string | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BANK_CARD_REGEX } from "../../constant/regex-pattern";
|
|
2
|
+
export function maskBankCard(text) {
|
|
3
|
+
if (!text || !BANK_CARD_REGEX.test(text)) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
var groups = [];
|
|
7
|
+
var remaining = text.length - 4;
|
|
8
|
+
while (remaining > 0) {
|
|
9
|
+
var size = Math.min(4, remaining);
|
|
10
|
+
groups.push('*'.repeat(size));
|
|
11
|
+
remaining -= size;
|
|
12
|
+
}
|
|
13
|
+
return groups.join(' ') + ' ' + text.substring(text.length - 4);
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function maskChineseIdCard(text?: string | null): string | undefined;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CHINESE_ID_CARD_REGEX } from "../../constant/regex-pattern";
|
|
2
|
+
export function maskChineseIdCard(text) {
|
|
3
|
+
if (!text || !CHINESE_ID_CARD_REGEX.test(text)) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
return text.substring(0, 3) + '*'.repeat(text.length - 7) + text.substring(text.length - 4);
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function maskChineseMobile(text?: string | null): string | undefined;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CHINESE_MOBILE_REGEX } from "../../constant/regex-pattern";
|
|
2
|
+
export function maskChineseMobile(text) {
|
|
3
|
+
if (!text || !CHINESE_MOBILE_REGEX.test(text)) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
var offset = text.length - 11;
|
|
7
|
+
return text.substring(0, offset + 3) + '****' + text.substring(offset + 7);
|
|
8
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CHINESE_NAME_REGEX } from "../../constant/regex-pattern";
|
|
2
|
+
export var CHINESE_COMPOUND_SURNAMES = ['欧阳', '上官', '司马', '诸葛', '东方', '慕容', '尉迟', '公孙', '夏侯', '长孙', '宇文', '司徒', '端木', '南宫', '皇甫', '令狐', '轩辕', '太史', '万俟', '闻人', '申屠', '宗政', '濮阳', '公冶', '太叔', '公羊', '赫连', '澹台', '拓跋', '呼延', '淳于', '单于'];
|
|
3
|
+
export function maskChineseName(text) {
|
|
4
|
+
if (!text || !CHINESE_NAME_REGEX.test(text)) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
return text.split('·').map(function (segment, index) {
|
|
8
|
+
var chars = Array.from(segment);
|
|
9
|
+
var keepLength = index === 0 && chars.length > 2 && CHINESE_COMPOUND_SURNAMES.includes(chars.slice(0, 2).join('')) ? 2 : 1;
|
|
10
|
+
return chars.slice(0, keepLength).join('') + '*'.repeat(chars.length - keepLength);
|
|
11
|
+
}).join('·');
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function maskEmail(text?: string | null): string | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EMAIL_REGEX } from "../../constant/regex-pattern";
|
|
2
|
+
export function maskEmail(text) {
|
|
3
|
+
if (!text || !EMAIL_REGEX.test(text)) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
var atIndex = text.indexOf('@');
|
|
7
|
+
var domain = text.substring(atIndex);
|
|
8
|
+
var localPart = text.substring(0, atIndex);
|
|
9
|
+
if (localPart.length <= 1) {
|
|
10
|
+
return '*' + domain;
|
|
11
|
+
}
|
|
12
|
+
return localPart.charAt(0) + '*'.repeat(localPart.length - 1) + domain;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function maskMobile(text?: string | null, alphaOrDial?: string): string | undefined;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { parsePhoneNumberFromString } from 'libphonenumber-js';
|
|
2
|
+
export function maskMobile(text, alphaOrDial) {
|
|
3
|
+
if (!text) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
var country;
|
|
7
|
+
var input = text;
|
|
8
|
+
if (alphaOrDial) {
|
|
9
|
+
if (/^[A-Za-z]{2}$/i.test(alphaOrDial)) {
|
|
10
|
+
country = alphaOrDial.toUpperCase();
|
|
11
|
+
} else if (!text.startsWith('+')) {
|
|
12
|
+
input = '+' + alphaOrDial.replace(/^\+/, '') + text;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
var parsed;
|
|
16
|
+
try {
|
|
17
|
+
parsed = country ? parsePhoneNumberFromString(input, country) : parsePhoneNumberFromString(input);
|
|
18
|
+
} catch (_unused) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
if (!parsed || !parsed.country) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
var phone = parsed.nationalNumber;
|
|
25
|
+
if (phone.length < 8) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
return phone.slice(0, phone.length - 8) + '****' + phone.slice(phone.length - 4);
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unikue/ts-lang-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"title": "TsLangUtils",
|
|
5
5
|
"description": "Common lang utilities for typescript",
|
|
6
6
|
"homepage": "https://unikueltd.github.io/ts-lang-utils",
|
|
@@ -54,12 +54,13 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@babel/runtime": "^7.29.7",
|
|
56
56
|
"@imranbarbhuiya/duration": "^5.1.8",
|
|
57
|
+
"libphonenumber-js": "^1.13.13",
|
|
57
58
|
"lodash": "^4.18.1",
|
|
58
|
-
"nanoid": "^3.3.
|
|
59
|
+
"nanoid": "^3.3.19",
|
|
59
60
|
"universal-cookie": "^8.1.2"
|
|
60
61
|
},
|
|
61
62
|
"devDependencies": {
|
|
62
|
-
"@eslint/eslintrc": "^3.3.
|
|
63
|
+
"@eslint/eslintrc": "^3.3.7",
|
|
63
64
|
"@eslint/js": "^10.0.1",
|
|
64
65
|
"@types/jest": "^30.0.0",
|
|
65
66
|
"@types/lodash": "^4.17.25",
|
|
@@ -67,16 +68,16 @@
|
|
|
67
68
|
"@unikue/typedoc-plugin-raw-content": "^1.1.1",
|
|
68
69
|
"@unikue/typedoc-theme-dumi": "^1.1.3",
|
|
69
70
|
"del-cli": "^7.0.0",
|
|
70
|
-
"eslint": "^10.
|
|
71
|
-
"eslint-plugin-jest": "^29.16.
|
|
72
|
-
"father": "^4.6.
|
|
71
|
+
"eslint": "^10.10.0",
|
|
72
|
+
"eslint-plugin-jest": "^29.16.6",
|
|
73
|
+
"father": "^4.6.37",
|
|
73
74
|
"gh-pages": "^6.3.0",
|
|
74
|
-
"globals": "^17.
|
|
75
|
-
"jest-environment-jsdom": "^30.5.
|
|
75
|
+
"globals": "^17.12.0",
|
|
76
|
+
"jest-environment-jsdom": "^30.5.1",
|
|
76
77
|
"ts-jest": "^29.4.12",
|
|
77
78
|
"typedoc": "~0.28.20",
|
|
78
79
|
"typescript": "^6.0.3",
|
|
79
|
-
"typescript-eslint": "^8.
|
|
80
|
+
"typescript-eslint": "^8.70.0"
|
|
80
81
|
},
|
|
81
82
|
"peerDependencies": {
|
|
82
83
|
"typescript": ">=4.0.0"
|
|
@@ -118,10 +119,10 @@
|
|
|
118
119
|
}
|
|
119
120
|
],
|
|
120
121
|
"allowScripts": {
|
|
121
|
-
"core-js": true,
|
|
122
|
-
"core-js-pure": true,
|
|
123
|
-
"esbuild": true,
|
|
124
|
-
"fsevents": true,
|
|
125
|
-
"unrs-resolver": true
|
|
122
|
+
"core-js@*": true,
|
|
123
|
+
"core-js-pure@*": true,
|
|
124
|
+
"esbuild@*": true,
|
|
125
|
+
"fsevents@*": true,
|
|
126
|
+
"unrs-resolver@*": true
|
|
126
127
|
}
|
|
127
128
|
}
|