@unikue/ts-lang-utils 1.2.11 → 1.2.13

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.
@@ -7,8 +7,10 @@ export { isAlphabeticUpper } from './isAlphabeticUpper';
7
7
  export { isAlphanumeric } from './isAlphanumeric';
8
8
  export { isAlphanumericLower } from './isAlphanumericLower';
9
9
  export { isAlphanumericUpper } from './isAlphanumericUpper';
10
+ export { isChinaIdCard } from './isChinaIdCard';
10
11
  export { isCompilable } from './isCompilable';
11
12
  export { isEmail } from './isEmail';
13
+ export { isMobile } from './isMobile';
12
14
  export { isNumeric } from './isNumeric';
13
15
  export { normalizePattern } from './normalizePattern';
14
16
  export { testResetting } from './testResetting';
@@ -28,8 +28,10 @@ __export(RegexUtils_exports, {
28
28
  isAlphanumeric: () => import_isAlphanumeric.isAlphanumeric,
29
29
  isAlphanumericLower: () => import_isAlphanumericLower.isAlphanumericLower,
30
30
  isAlphanumericUpper: () => import_isAlphanumericUpper.isAlphanumericUpper,
31
+ isChinaIdCard: () => import_isChinaIdCard.isChinaIdCard,
31
32
  isCompilable: () => import_isCompilable.isCompilable,
32
33
  isEmail: () => import_isEmail.isEmail,
34
+ isMobile: () => import_isMobile.isMobile,
33
35
  isNumeric: () => import_isNumeric.isNumeric,
34
36
  normalizePattern: () => import_normalizePattern.normalizePattern,
35
37
  testResetting: () => import_testResetting.testResetting,
@@ -45,8 +47,10 @@ var import_isAlphabeticUpper = require("./isAlphabeticUpper");
45
47
  var import_isAlphanumeric = require("./isAlphanumeric");
46
48
  var import_isAlphanumericLower = require("./isAlphanumericLower");
47
49
  var import_isAlphanumericUpper = require("./isAlphanumericUpper");
50
+ var import_isChinaIdCard = require("./isChinaIdCard");
48
51
  var import_isCompilable = require("./isCompilable");
49
52
  var import_isEmail = require("./isEmail");
53
+ var import_isMobile = require("./isMobile");
50
54
  var import_isNumeric = require("./isNumeric");
51
55
  var import_normalizePattern = require("./normalizePattern");
52
56
  var import_testResetting = require("./testResetting");
@@ -62,8 +66,10 @@ var import_unescapePattern = require("./unescapePattern");
62
66
  isAlphanumeric,
63
67
  isAlphanumericLower,
64
68
  isAlphanumericUpper,
69
+ isChinaIdCard,
65
70
  isCompilable,
66
71
  isEmail,
72
+ isMobile,
67
73
  isNumeric,
68
74
  normalizePattern,
69
75
  testResetting,
@@ -0,0 +1,2 @@
1
+ export declare const CHINA_ID_CARD_REGEX: RegExp;
2
+ export declare function isChinaIdCard(text?: string | null, checksum?: boolean): boolean;
@@ -0,0 +1,53 @@
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/isChinaIdCard.ts
20
+ var isChinaIdCard_exports = {};
21
+ __export(isChinaIdCard_exports, {
22
+ CHINA_ID_CARD_REGEX: () => CHINA_ID_CARD_REGEX,
23
+ isChinaIdCard: () => isChinaIdCard
24
+ });
25
+ module.exports = __toCommonJS(isChinaIdCard_exports);
26
+ var CHINA_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]$/;
27
+ var CHECKSUM_WEIGHTS = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
28
+ var CHECKSUM_CODES = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"];
29
+ function isChinaIdCard(text, checksum = true) {
30
+ if (!text || !CHINA_ID_CARD_REGEX.test(text)) {
31
+ return false;
32
+ }
33
+ const year = parseInt(text.substring(6, 10), 10);
34
+ const month = parseInt(text.substring(10, 12), 10);
35
+ const day = parseInt(text.substring(12, 14), 10);
36
+ const date = new Date(year, month - 1, day);
37
+ if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) {
38
+ return false;
39
+ }
40
+ if (!checksum) {
41
+ return true;
42
+ }
43
+ let sum = 0;
44
+ for (let i = 0; i < 17; i++) {
45
+ sum += parseInt(text.charAt(i), 10) * CHECKSUM_WEIGHTS[i];
46
+ }
47
+ return CHECKSUM_CODES[sum % 11] === text.charAt(17).toUpperCase();
48
+ }
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ CHINA_ID_CARD_REGEX,
52
+ isChinaIdCard
53
+ });
@@ -1 +1,2 @@
1
+ export declare const EMAIL_REGEX: RegExp;
1
2
  export declare function isEmail(text?: string | null): boolean;
@@ -19,13 +19,16 @@ 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,
22
23
  isEmail: () => isEmail
23
24
  });
24
25
  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
27
  function isEmail(text) {
26
- return !!text && /^[A-Za-z0-9._%+-]+@[-A-Za-z0-9.]+\.[A-Za-z]{2,}$/.test(text);
28
+ return !!text && EMAIL_REGEX.test(text);
27
29
  }
28
30
  // Annotate the CommonJS export names for ESM import in node:
29
31
  0 && (module.exports = {
32
+ EMAIL_REGEX,
30
33
  isEmail
31
34
  });
@@ -0,0 +1,2 @@
1
+ export declare const CHINA_MOBILE_REGEX: RegExp;
2
+ export declare function isMobile(text?: string | null, pattern?: string | RegExp): boolean;
@@ -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/RegexUtils/isMobile.ts
20
+ var isMobile_exports = {};
21
+ __export(isMobile_exports, {
22
+ CHINA_MOBILE_REGEX: () => CHINA_MOBILE_REGEX,
23
+ isMobile: () => isMobile
24
+ });
25
+ module.exports = __toCommonJS(isMobile_exports);
26
+ var import_compilePattern = require("./compilePattern");
27
+ var CHINA_MOBILE_REGEX = /^1[3-9]\d{9}$/;
28
+ function isMobile(text, pattern = CHINA_MOBILE_REGEX) {
29
+ if (!text) {
30
+ return false;
31
+ }
32
+ if (typeof pattern === "string") {
33
+ const regex = (0, import_compilePattern.compilePattern)(pattern);
34
+ return !!regex && regex.test(text);
35
+ }
36
+ return pattern.test(text);
37
+ }
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ CHINA_MOBILE_REGEX,
41
+ isMobile
42
+ });
@@ -7,8 +7,10 @@ export { isAlphabeticUpper } from './isAlphabeticUpper';
7
7
  export { isAlphanumeric } from './isAlphanumeric';
8
8
  export { isAlphanumericLower } from './isAlphanumericLower';
9
9
  export { isAlphanumericUpper } from './isAlphanumericUpper';
10
+ export { isChinaIdCard } from './isChinaIdCard';
10
11
  export { isCompilable } from './isCompilable';
11
12
  export { isEmail } from './isEmail';
13
+ export { isMobile } from './isMobile';
12
14
  export { isNumeric } from './isNumeric';
13
15
  export { normalizePattern } from './normalizePattern';
14
16
  export { testResetting } from './testResetting';
@@ -7,8 +7,10 @@ export { isAlphabeticUpper } from "./isAlphabeticUpper";
7
7
  export { isAlphanumeric } from "./isAlphanumeric";
8
8
  export { isAlphanumericLower } from "./isAlphanumericLower";
9
9
  export { isAlphanumericUpper } from "./isAlphanumericUpper";
10
+ export { isChinaIdCard } from "./isChinaIdCard";
10
11
  export { isCompilable } from "./isCompilable";
11
12
  export { isEmail } from "./isEmail";
13
+ export { isMobile } from "./isMobile";
12
14
  export { isNumeric } from "./isNumeric";
13
15
  export { normalizePattern } from "./normalizePattern";
14
16
  export { testResetting } from "./testResetting";
@@ -0,0 +1,2 @@
1
+ export declare const CHINA_ID_CARD_REGEX: RegExp;
2
+ export declare function isChinaIdCard(text?: string | null, checksum?: boolean): boolean;
@@ -0,0 +1,24 @@
1
+ export var CHINA_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]$/;
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 isChinaIdCard(text) {
5
+ var checksum = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
6
+ if (!text || !CHINA_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 +1,2 @@
1
+ export declare const EMAIL_REGEX: RegExp;
1
2
  export declare function isEmail(text?: string | null): boolean;
@@ -1,3 +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
2
  export function isEmail(text) {
2
- return !!text && /^[A-Za-z0-9._%+-]+@[-A-Za-z0-9.]+\.[A-Za-z]{2,}$/.test(text);
3
+ return !!text && EMAIL_REGEX.test(text);
3
4
  }
@@ -0,0 +1,2 @@
1
+ export declare const CHINA_MOBILE_REGEX: RegExp;
2
+ export declare function isMobile(text?: string | null, pattern?: string | RegExp): boolean;
@@ -0,0 +1,13 @@
1
+ import { compilePattern } from "./compilePattern";
2
+ export var CHINA_MOBILE_REGEX = /^1[3-9]\d{9}$/;
3
+ export function isMobile(text) {
4
+ var pattern = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : CHINA_MOBILE_REGEX;
5
+ if (!text) {
6
+ return false;
7
+ }
8
+ if (typeof pattern === 'string') {
9
+ var regex = compilePattern(pattern);
10
+ return !!regex && regex.test(text);
11
+ }
12
+ return pattern.test(text);
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unikue/ts-lang-utils",
3
- "version": "1.2.11",
3
+ "version": "1.2.13",
4
4
  "title": "TsLangUtils",
5
5
  "description": "Common lang utilities for typescript",
6
6
  "homepage": "https://unikueltd.github.io/ts-lang-utils",
@@ -55,28 +55,28 @@
55
55
  "@babel/runtime": "^7.29.7",
56
56
  "@imranbarbhuiya/duration": "^5.1.8",
57
57
  "lodash": "^4.18.1",
58
- "nanoid": "^3.3.16",
58
+ "nanoid": "^3.3.18",
59
59
  "universal-cookie": "^8.1.2"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@eslint/eslintrc": "^3.3.6",
63
63
  "@eslint/js": "^10.0.1",
64
64
  "@types/jest": "^30.0.0",
65
- "@types/lodash": "^4.17.24",
65
+ "@types/lodash": "^4.17.25",
66
66
  "@unikue/babel-plugin-remove-comment": "^1.2.1",
67
67
  "@unikue/typedoc-plugin-raw-content": "^1.1.1",
68
68
  "@unikue/typedoc-theme-dumi": "^1.1.3",
69
69
  "del-cli": "^7.0.0",
70
- "eslint": "^10.7.0",
71
- "eslint-plugin-jest": "^29.15.4",
72
- "father": "^4.6.31",
70
+ "eslint": "^10.9.1",
71
+ "eslint-plugin-jest": "^29.16.5",
72
+ "father": "^4.6.36",
73
73
  "gh-pages": "^6.3.0",
74
- "globals": "^17.7.0",
75
- "jest-environment-jsdom": "^30.4.1",
76
- "ts-jest": "^29.4.11",
74
+ "globals": "^17.11.0",
75
+ "jest-environment-jsdom": "^30.5.0",
76
+ "ts-jest": "^29.4.12",
77
77
  "typedoc": "~0.28.20",
78
78
  "typescript": "^6.0.3",
79
- "typescript-eslint": "^8.64.0"
79
+ "typescript-eslint": "^8.68.0"
80
80
  },
81
81
  "peerDependencies": {
82
82
  "typescript": ">=4.0.0"