@unikue/ts-lang-utils 1.2.12 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/cjs/constant/regex-pattern.d.ts +5 -0
  2. package/dist/cjs/constant/regex-pattern.js +41 -0
  3. package/dist/cjs/index.d.ts +1 -0
  4. package/dist/cjs/index.js +3 -0
  5. package/dist/cjs/util/RegexUtils/index.d.ts +1 -0
  6. package/dist/cjs/util/RegexUtils/index.js +3 -0
  7. package/dist/cjs/util/RegexUtils/isChineseIdCard.d.ts +1 -0
  8. package/dist/cjs/util/RegexUtils/isChineseIdCard.js +51 -0
  9. package/dist/cjs/util/RegexUtils/isEmail.d.ts +0 -1
  10. package/dist/cjs/util/RegexUtils/isEmail.js +2 -4
  11. package/dist/cjs/util/RegexUtils/isMobile.d.ts +0 -1
  12. package/dist/cjs/util/RegexUtils/isMobile.js +2 -4
  13. package/dist/cjs/util/SensitiveUtils/index.d.ts +5 -0
  14. package/dist/cjs/util/SensitiveUtils/index.js +41 -0
  15. package/dist/cjs/util/SensitiveUtils/maskBankCard.d.ts +1 -0
  16. package/dist/cjs/util/SensitiveUtils/maskBankCard.js +42 -0
  17. package/dist/cjs/util/SensitiveUtils/maskChineseIdCard.d.ts +1 -0
  18. package/dist/cjs/util/SensitiveUtils/maskChineseIdCard.js +35 -0
  19. package/dist/cjs/util/SensitiveUtils/maskChineseMobile.d.ts +1 -0
  20. package/dist/cjs/util/SensitiveUtils/maskChineseMobile.js +36 -0
  21. package/dist/cjs/util/SensitiveUtils/maskChineseName.d.ts +2 -0
  22. package/dist/cjs/util/SensitiveUtils/maskChineseName.js +75 -0
  23. package/dist/cjs/util/SensitiveUtils/maskEmail.d.ts +1 -0
  24. package/dist/cjs/util/SensitiveUtils/maskEmail.js +41 -0
  25. package/dist/esm/constant/regex-pattern.d.ts +5 -0
  26. package/dist/esm/constant/regex-pattern.js +5 -0
  27. package/dist/esm/index.d.ts +1 -0
  28. package/dist/esm/index.js +2 -0
  29. package/dist/esm/util/RegexUtils/index.d.ts +1 -0
  30. package/dist/esm/util/RegexUtils/index.js +1 -0
  31. package/dist/esm/util/RegexUtils/isChineseIdCard.d.ts +1 -0
  32. package/dist/esm/util/RegexUtils/isChineseIdCard.js +24 -0
  33. package/dist/esm/util/RegexUtils/isEmail.d.ts +0 -1
  34. package/dist/esm/util/RegexUtils/isEmail.js +1 -1
  35. package/dist/esm/util/RegexUtils/isMobile.d.ts +0 -1
  36. package/dist/esm/util/RegexUtils/isMobile.js +2 -2
  37. package/dist/esm/util/SensitiveUtils/index.d.ts +5 -0
  38. package/dist/esm/util/SensitiveUtils/index.js +5 -0
  39. package/dist/esm/util/SensitiveUtils/maskBankCard.d.ts +1 -0
  40. package/dist/esm/util/SensitiveUtils/maskBankCard.js +14 -0
  41. package/dist/esm/util/SensitiveUtils/maskChineseIdCard.d.ts +1 -0
  42. package/dist/esm/util/SensitiveUtils/maskChineseIdCard.js +7 -0
  43. package/dist/esm/util/SensitiveUtils/maskChineseMobile.d.ts +1 -0
  44. package/dist/esm/util/SensitiveUtils/maskChineseMobile.js +8 -0
  45. package/dist/esm/util/SensitiveUtils/maskChineseName.d.ts +2 -0
  46. package/dist/esm/util/SensitiveUtils/maskChineseName.js +12 -0
  47. package/dist/esm/util/SensitiveUtils/maskEmail.d.ts +1 -0
  48. package/dist/esm/util/SensitiveUtils/maskEmail.js +13 -0
  49. package/package.json +1 -1
@@ -0,0 +1,5 @@
1
+ export declare const BANK_CARD_REGEX: RegExp;
2
+ export declare const CHINESE_ID_CARD_REGEX: RegExp;
3
+ export declare const CHINESE_MOBILE_REGEX: RegExp;
4
+ export declare const CHINESE_NAME_REGEX: RegExp;
5
+ export declare const EMAIL_REGEX: RegExp;
@@ -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
+ });
@@ -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,6 +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 { isChineseIdCard } from './isChineseIdCard';
10
11
  export { isCompilable } from './isCompilable';
11
12
  export { isEmail } from './isEmail';
12
13
  export { isMobile } from './isMobile';
@@ -28,6 +28,7 @@ __export(RegexUtils_exports, {
28
28
  isAlphanumeric: () => import_isAlphanumeric.isAlphanumeric,
29
29
  isAlphanumericLower: () => import_isAlphanumericLower.isAlphanumericLower,
30
30
  isAlphanumericUpper: () => import_isAlphanumericUpper.isAlphanumericUpper,
31
+ isChineseIdCard: () => import_isChineseIdCard.isChineseIdCard,
31
32
  isCompilable: () => import_isCompilable.isCompilable,
32
33
  isEmail: () => import_isEmail.isEmail,
33
34
  isMobile: () => import_isMobile.isMobile,
@@ -46,6 +47,7 @@ var import_isAlphabeticUpper = require("./isAlphabeticUpper");
46
47
  var import_isAlphanumeric = require("./isAlphanumeric");
47
48
  var import_isAlphanumericLower = require("./isAlphanumericLower");
48
49
  var import_isAlphanumericUpper = require("./isAlphanumericUpper");
50
+ var import_isChineseIdCard = require("./isChineseIdCard");
49
51
  var import_isCompilable = require("./isCompilable");
50
52
  var import_isEmail = require("./isEmail");
51
53
  var import_isMobile = require("./isMobile");
@@ -64,6 +66,7 @@ var import_unescapePattern = require("./unescapePattern");
64
66
  isAlphanumeric,
65
67
  isAlphanumericLower,
66
68
  isAlphanumericUpper,
69
+ isChineseIdCard,
67
70
  isCompilable,
68
71
  isEmail,
69
72
  isMobile,
@@ -0,0 +1 @@
1
+ export declare function isChineseIdCard(text?: string | null, checksum?: boolean): boolean;
@@ -0,0 +1,51 @@
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/RegexUtils/isChineseIdCard.ts
20
+ var isChineseIdCard_exports = {};
21
+ __export(isChineseIdCard_exports, {
22
+ isChineseIdCard: () => isChineseIdCard
23
+ });
24
+ module.exports = __toCommonJS(isChineseIdCard_exports);
25
+ var import_regex_pattern = require("../../constant/regex-pattern");
26
+ var CHECKSUM_WEIGHTS = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
27
+ var CHECKSUM_CODES = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"];
28
+ function isChineseIdCard(text, checksum = true) {
29
+ if (!text || !import_regex_pattern.CHINESE_ID_CARD_REGEX.test(text)) {
30
+ return false;
31
+ }
32
+ const year = parseInt(text.substring(6, 10), 10);
33
+ const month = parseInt(text.substring(10, 12), 10);
34
+ const day = parseInt(text.substring(12, 14), 10);
35
+ const date = new Date(year, month - 1, day);
36
+ if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) {
37
+ return false;
38
+ }
39
+ if (!checksum) {
40
+ return true;
41
+ }
42
+ let sum = 0;
43
+ for (let i = 0; i < 17; i++) {
44
+ sum += parseInt(text.charAt(i), 10) * CHECKSUM_WEIGHTS[i];
45
+ }
46
+ return CHECKSUM_CODES[sum % 11] === text.charAt(17).toUpperCase();
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ isChineseIdCard
51
+ });
@@ -1,2 +1 @@
1
- export declare const EMAIL_REGEX: RegExp;
2
1
  export declare function isEmail(text?: string | null): boolean;
@@ -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 EMAIL_REGEX = /^[^\s@]+@[A-Za-z0-9\u00A0-\uFFFF-]+(?:\.[A-Za-z0-9\u00A0-\uFFFF-]+)*\.[A-Za-z\u00A0-\uFFFF]{2,}$/;
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 const CHINA_MOBILE_REGEX: RegExp;
2
1
  export declare function isMobile(text?: string | null, pattern?: string | RegExp): boolean;
@@ -19,13 +19,12 @@ 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 CHINA_MOBILE_REGEX = /^1[3-9]\d{9}$/;
28
- function isMobile(text, pattern = CHINA_MOBILE_REGEX) {
27
+ function isMobile(text, pattern = import_regex_pattern.CHINESE_MOBILE_REGEX) {
29
28
  if (!text) {
30
29
  return false;
31
30
  }
@@ -37,6 +36,5 @@ function isMobile(text, pattern = CHINA_MOBILE_REGEX) {
37
36
  }
38
37
  // Annotate the CommonJS export names for ESM import in node:
39
38
  0 && (module.exports = {
40
- CHINA_MOBILE_REGEX,
41
39
  isMobile
42
40
  });
@@ -0,0 +1,5 @@
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';
@@ -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/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
+ });
28
+ module.exports = __toCommonJS(SensitiveUtils_exports);
29
+ var import_maskBankCard = require("./maskBankCard");
30
+ var import_maskChineseIdCard = require("./maskChineseIdCard");
31
+ var import_maskChineseMobile = require("./maskChineseMobile");
32
+ var import_maskChineseName = require("./maskChineseName");
33
+ var import_maskEmail = require("./maskEmail");
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ maskBankCard,
37
+ maskChineseIdCard,
38
+ maskChineseMobile,
39
+ maskChineseName,
40
+ maskEmail
41
+ });
@@ -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,2 @@
1
+ export declare const CHINESE_COMPOUND_SURNAMES: string[];
2
+ export declare function maskChineseName(text?: string | null): string | undefined;
@@ -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,5 @@
1
+ export declare const BANK_CARD_REGEX: RegExp;
2
+ export declare const CHINESE_ID_CARD_REGEX: RegExp;
3
+ export declare const CHINESE_MOBILE_REGEX: RegExp;
4
+ export declare const CHINESE_NAME_REGEX: RegExp;
5
+ export declare const EMAIL_REGEX: RegExp;
@@ -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,}$/;
@@ -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,6 +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 { isChineseIdCard } from './isChineseIdCard';
10
11
  export { isCompilable } from './isCompilable';
11
12
  export { isEmail } from './isEmail';
12
13
  export { isMobile } from './isMobile';
@@ -7,6 +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 { isChineseIdCard } from "./isChineseIdCard";
10
11
  export { isCompilable } from "./isCompilable";
11
12
  export { isEmail } from "./isEmail";
12
13
  export { isMobile } from "./isMobile";
@@ -0,0 +1 @@
1
+ export declare function isChineseIdCard(text?: string | null, checksum?: boolean): boolean;
@@ -0,0 +1,24 @@
1
+ import { CHINESE_ID_CARD_REGEX } from "../../constant/regex-pattern";
2
+ var CHECKSUM_WEIGHTS = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
3
+ var CHECKSUM_CODES = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
4
+ export function isChineseIdCard(text) {
5
+ var checksum = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
6
+ if (!text || !CHINESE_ID_CARD_REGEX.test(text)) {
7
+ return false;
8
+ }
9
+ var year = parseInt(text.substring(6, 10), 10);
10
+ var month = parseInt(text.substring(10, 12), 10);
11
+ var day = parseInt(text.substring(12, 14), 10);
12
+ var date = new Date(year, month - 1, day);
13
+ if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) {
14
+ return false;
15
+ }
16
+ if (!checksum) {
17
+ return true;
18
+ }
19
+ var sum = 0;
20
+ for (var i = 0; i < 17; i++) {
21
+ sum += parseInt(text.charAt(i), 10) * CHECKSUM_WEIGHTS[i];
22
+ }
23
+ return CHECKSUM_CODES[sum % 11] === text.charAt(17).toUpperCase();
24
+ }
@@ -1,2 +1 @@
1
- export declare const EMAIL_REGEX: RegExp;
2
1
  export declare function isEmail(text?: string | null): boolean;
@@ -1,4 +1,4 @@
1
- export var EMAIL_REGEX = /^[^\s@]+@[A-Za-z0-9\u00A0-\uFFFF-]+(?:\.[A-Za-z0-9\u00A0-\uFFFF-]+)*\.[A-Za-z\u00A0-\uFFFF]{2,}$/;
1
+ import { EMAIL_REGEX } from "../../constant/regex-pattern";
2
2
  export function isEmail(text) {
3
3
  return !!text && EMAIL_REGEX.test(text);
4
4
  }
@@ -1,2 +1 @@
1
- export declare const CHINA_MOBILE_REGEX: RegExp;
2
1
  export declare function isMobile(text?: string | null, pattern?: string | RegExp): boolean;
@@ -1,7 +1,7 @@
1
+ import { CHINESE_MOBILE_REGEX } from "../../constant/regex-pattern";
1
2
  import { compilePattern } from "./compilePattern";
2
- export var CHINA_MOBILE_REGEX = /^1[3-9]\d{9}$/;
3
3
  export function isMobile(text) {
4
- var pattern = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : CHINA_MOBILE_REGEX;
4
+ var pattern = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : CHINESE_MOBILE_REGEX;
5
5
  if (!text) {
6
6
  return false;
7
7
  }
@@ -0,0 +1,5 @@
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';
@@ -0,0 +1,5 @@
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";
@@ -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,2 @@
1
+ export declare const CHINESE_COMPOUND_SURNAMES: string[];
2
+ export declare function maskChineseName(text?: string | null): string | undefined;
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unikue/ts-lang-utils",
3
- "version": "1.2.12",
3
+ "version": "1.3.0",
4
4
  "title": "TsLangUtils",
5
5
  "description": "Common lang utilities for typescript",
6
6
  "homepage": "https://unikueltd.github.io/ts-lang-utils",