@unikue/ts-lang-utils 1.2.10 → 1.2.12
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/util/FileUtils/formatBytes.d.ts +1 -0
- package/dist/cjs/util/FileUtils/formatBytes.js +45 -0
- package/dist/cjs/util/FileUtils/index.d.ts +1 -0
- package/dist/cjs/util/FileUtils/index.js +3 -0
- package/dist/cjs/util/RegexUtils/index.d.ts +1 -0
- package/dist/cjs/util/RegexUtils/index.js +3 -0
- package/dist/cjs/util/RegexUtils/isEmail.d.ts +1 -0
- package/dist/cjs/util/RegexUtils/isEmail.js +4 -1
- package/dist/cjs/util/RegexUtils/isMobile.d.ts +2 -0
- package/dist/cjs/util/RegexUtils/isMobile.js +42 -0
- package/dist/esm/util/FileUtils/formatBytes.d.ts +1 -0
- package/dist/esm/util/FileUtils/formatBytes.js +18 -0
- package/dist/esm/util/FileUtils/index.d.ts +1 -0
- package/dist/esm/util/FileUtils/index.js +1 -0
- package/dist/esm/util/RegexUtils/index.d.ts +1 -0
- package/dist/esm/util/RegexUtils/index.js +1 -0
- package/dist/esm/util/RegexUtils/isEmail.d.ts +1 -0
- package/dist/esm/util/RegexUtils/isEmail.js +2 -1
- package/dist/esm/util/RegexUtils/isMobile.d.ts +2 -0
- package/dist/esm/util/RegexUtils/isMobile.js +13 -0
- package/package.json +12 -12
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatBytes(bytes?: number | null, precision?: number): string | undefined;
|
|
@@ -0,0 +1,45 @@
|
|
|
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/FileUtils/formatBytes.ts
|
|
20
|
+
var formatBytes_exports = {};
|
|
21
|
+
__export(formatBytes_exports, {
|
|
22
|
+
formatBytes: () => formatBytes
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(formatBytes_exports);
|
|
25
|
+
function formatBytes(bytes, precision = 2) {
|
|
26
|
+
if (bytes === void 0 || bytes === null) {
|
|
27
|
+
return void 0;
|
|
28
|
+
}
|
|
29
|
+
if (bytes <= 0 || !Number.isFinite(bytes)) {
|
|
30
|
+
return "0 B";
|
|
31
|
+
}
|
|
32
|
+
const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB"];
|
|
33
|
+
const base = 1024;
|
|
34
|
+
let unitIndex = 0;
|
|
35
|
+
let value = bytes;
|
|
36
|
+
while (value >= base && unitIndex < units.length - 1) {
|
|
37
|
+
value /= base;
|
|
38
|
+
unitIndex++;
|
|
39
|
+
}
|
|
40
|
+
return `${parseFloat(value.toFixed(precision))} ${units[unitIndex]}`;
|
|
41
|
+
}
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
formatBytes
|
|
45
|
+
});
|
|
@@ -19,11 +19,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/util/FileUtils/index.ts
|
|
20
20
|
var FileUtils_exports = {};
|
|
21
21
|
__export(FileUtils_exports, {
|
|
22
|
+
formatBytes: () => import_formatBytes.formatBytes,
|
|
22
23
|
readAsDataUrl: () => import_readAsDataUrl.readAsDataUrl
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(FileUtils_exports);
|
|
26
|
+
var import_formatBytes = require("./formatBytes");
|
|
25
27
|
var import_readAsDataUrl = require("./readAsDataUrl");
|
|
26
28
|
// Annotate the CommonJS export names for ESM import in node:
|
|
27
29
|
0 && (module.exports = {
|
|
30
|
+
formatBytes,
|
|
28
31
|
readAsDataUrl
|
|
29
32
|
});
|
|
@@ -9,6 +9,7 @@ export { isAlphanumericLower } from './isAlphanumericLower';
|
|
|
9
9
|
export { isAlphanumericUpper } from './isAlphanumericUpper';
|
|
10
10
|
export { isCompilable } from './isCompilable';
|
|
11
11
|
export { isEmail } from './isEmail';
|
|
12
|
+
export { isMobile } from './isMobile';
|
|
12
13
|
export { isNumeric } from './isNumeric';
|
|
13
14
|
export { normalizePattern } from './normalizePattern';
|
|
14
15
|
export { testResetting } from './testResetting';
|
|
@@ -30,6 +30,7 @@ __export(RegexUtils_exports, {
|
|
|
30
30
|
isAlphanumericUpper: () => import_isAlphanumericUpper.isAlphanumericUpper,
|
|
31
31
|
isCompilable: () => import_isCompilable.isCompilable,
|
|
32
32
|
isEmail: () => import_isEmail.isEmail,
|
|
33
|
+
isMobile: () => import_isMobile.isMobile,
|
|
33
34
|
isNumeric: () => import_isNumeric.isNumeric,
|
|
34
35
|
normalizePattern: () => import_normalizePattern.normalizePattern,
|
|
35
36
|
testResetting: () => import_testResetting.testResetting,
|
|
@@ -47,6 +48,7 @@ var import_isAlphanumericLower = require("./isAlphanumericLower");
|
|
|
47
48
|
var import_isAlphanumericUpper = require("./isAlphanumericUpper");
|
|
48
49
|
var import_isCompilable = require("./isCompilable");
|
|
49
50
|
var import_isEmail = require("./isEmail");
|
|
51
|
+
var import_isMobile = require("./isMobile");
|
|
50
52
|
var import_isNumeric = require("./isNumeric");
|
|
51
53
|
var import_normalizePattern = require("./normalizePattern");
|
|
52
54
|
var import_testResetting = require("./testResetting");
|
|
@@ -64,6 +66,7 @@ var import_unescapePattern = require("./unescapePattern");
|
|
|
64
66
|
isAlphanumericUpper,
|
|
65
67
|
isCompilable,
|
|
66
68
|
isEmail,
|
|
69
|
+
isMobile,
|
|
67
70
|
isNumeric,
|
|
68
71
|
normalizePattern,
|
|
69
72
|
testResetting,
|
|
@@ -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 &&
|
|
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,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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatBytes(bytes?: number | null, precision?: number): string | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function formatBytes(bytes) {
|
|
2
|
+
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
3
|
+
if (bytes === undefined || bytes === null) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
if (bytes <= 0 || !Number.isFinite(bytes)) {
|
|
7
|
+
return '0 B';
|
|
8
|
+
}
|
|
9
|
+
var units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'];
|
|
10
|
+
var base = 1024;
|
|
11
|
+
var unitIndex = 0;
|
|
12
|
+
var value = bytes;
|
|
13
|
+
while (value >= base && unitIndex < units.length - 1) {
|
|
14
|
+
value /= base;
|
|
15
|
+
unitIndex++;
|
|
16
|
+
}
|
|
17
|
+
return "".concat(parseFloat(value.toFixed(precision)), " ").concat(units[unitIndex]);
|
|
18
|
+
}
|
|
@@ -9,6 +9,7 @@ export { isAlphanumericLower } from './isAlphanumericLower';
|
|
|
9
9
|
export { isAlphanumericUpper } from './isAlphanumericUpper';
|
|
10
10
|
export { isCompilable } from './isCompilable';
|
|
11
11
|
export { isEmail } from './isEmail';
|
|
12
|
+
export { isMobile } from './isMobile';
|
|
12
13
|
export { isNumeric } from './isNumeric';
|
|
13
14
|
export { normalizePattern } from './normalizePattern';
|
|
14
15
|
export { testResetting } from './testResetting';
|
|
@@ -9,6 +9,7 @@ export { isAlphanumericLower } from "./isAlphanumericLower";
|
|
|
9
9
|
export { isAlphanumericUpper } from "./isAlphanumericUpper";
|
|
10
10
|
export { isCompilable } from "./isCompilable";
|
|
11
11
|
export { isEmail } from "./isEmail";
|
|
12
|
+
export { isMobile } from "./isMobile";
|
|
12
13
|
export { isNumeric } from "./isNumeric";
|
|
13
14
|
export { normalizePattern } from "./normalizePattern";
|
|
14
15
|
export { testResetting } from "./testResetting";
|
|
@@ -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 &&
|
|
3
|
+
return !!text && EMAIL_REGEX.test(text);
|
|
3
4
|
}
|
|
@@ -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.
|
|
3
|
+
"version": "1.2.12",
|
|
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.
|
|
58
|
+
"nanoid": "^3.3.18",
|
|
59
59
|
"universal-cookie": "^8.1.2"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@eslint/eslintrc": "^3.3.
|
|
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.
|
|
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.
|
|
71
|
-
"eslint-plugin-jest": "^29.
|
|
72
|
-
"father": "^4.6.
|
|
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.
|
|
75
|
-
"jest-environment-jsdom": "^30.
|
|
76
|
-
"ts-jest": "^29.4.
|
|
77
|
-
"typedoc": "~0.28.
|
|
74
|
+
"globals": "^17.11.0",
|
|
75
|
+
"jest-environment-jsdom": "^30.5.0",
|
|
76
|
+
"ts-jest": "^29.4.12",
|
|
77
|
+
"typedoc": "~0.28.20",
|
|
78
78
|
"typescript": "^6.0.3",
|
|
79
|
-
"typescript-eslint": "^8.
|
|
79
|
+
"typescript-eslint": "^8.68.0"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
82
|
"typescript": ">=4.0.0"
|