@unikue/ts-lang-utils 1.2.8 → 1.2.10
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/ImageUtils/extractExtension.d.ts +1 -0
- package/dist/cjs/util/ImageUtils/extractExtension.js +62 -0
- package/dist/cjs/util/ImageUtils/index.d.ts +1 -0
- package/dist/cjs/util/ImageUtils/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 +31 -0
- package/dist/esm/util/ImageUtils/extractExtension.d.ts +1 -0
- package/dist/esm/util/ImageUtils/extractExtension.js +38 -0
- package/dist/esm/util/ImageUtils/index.d.ts +1 -0
- package/dist/esm/util/ImageUtils/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 +3 -0
- package/package.json +5 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function extractExtension(imageSource?: string | null, allowedExtensions?: Array<string | null | undefined>, fallback?: string): string;
|
|
@@ -0,0 +1,62 @@
|
|
|
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/ImageUtils/extractExtension.ts
|
|
20
|
+
var extractExtension_exports = {};
|
|
21
|
+
__export(extractExtension_exports, {
|
|
22
|
+
extractExtension: () => extractExtension
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(extractExtension_exports);
|
|
25
|
+
var import_UriUtils = require("../UriUtils");
|
|
26
|
+
var import_UriUtils2 = require("../UriUtils");
|
|
27
|
+
var DEFAULT_EXTENSIONS = [".jpg", ".jpeg", ".png", ".gif", ".webp", ".bmp", ".heic", ".heif", ".svg"];
|
|
28
|
+
function extractExtension(imageSource, allowedExtensions = DEFAULT_EXTENSIONS, fallback = ".jpg") {
|
|
29
|
+
if (!imageSource) {
|
|
30
|
+
return fallback;
|
|
31
|
+
}
|
|
32
|
+
let pathOnly = imageSource;
|
|
33
|
+
if ((0, import_UriUtils.isHttp)(imageSource) || (0, import_UriUtils2.isHttps)(imageSource)) {
|
|
34
|
+
const qIndex = pathOnly.indexOf("?");
|
|
35
|
+
const hIndex = pathOnly.indexOf("#");
|
|
36
|
+
let cutoff = pathOnly.length;
|
|
37
|
+
if (qIndex !== -1) {
|
|
38
|
+
cutoff = Math.min(cutoff, qIndex);
|
|
39
|
+
}
|
|
40
|
+
if (hIndex !== -1) {
|
|
41
|
+
cutoff = Math.min(cutoff, hIndex);
|
|
42
|
+
}
|
|
43
|
+
pathOnly = pathOnly.substring(0, cutoff);
|
|
44
|
+
}
|
|
45
|
+
const lastDot = pathOnly.lastIndexOf(".");
|
|
46
|
+
if (lastDot === -1) {
|
|
47
|
+
return fallback;
|
|
48
|
+
}
|
|
49
|
+
const ext = pathOnly.substring(lastDot).toLowerCase();
|
|
50
|
+
if (ext === ".") {
|
|
51
|
+
return fallback;
|
|
52
|
+
}
|
|
53
|
+
if (allowedExtensions && allowedExtensions.length) {
|
|
54
|
+
const lowerExtensions = allowedExtensions.map((e) => e == null ? void 0 : e.toLowerCase());
|
|
55
|
+
return lowerExtensions.includes(ext) ? ext : fallback;
|
|
56
|
+
}
|
|
57
|
+
return ext;
|
|
58
|
+
}
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
extractExtension
|
|
62
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { detectDimension } from './detectDimension';
|
|
2
2
|
export { detectSource } from './detectSource';
|
|
3
|
+
export { extractExtension } from './extractExtension';
|
|
3
4
|
export { isImage } from './isImage';
|
|
4
5
|
export { isGifImage } from './isGifImage';
|
|
5
6
|
export { isJpgImage } from './isJpgImage';
|
|
@@ -21,6 +21,7 @@ var ImageUtils_exports = {};
|
|
|
21
21
|
__export(ImageUtils_exports, {
|
|
22
22
|
detectDimension: () => import_detectDimension.detectDimension,
|
|
23
23
|
detectSource: () => import_detectSource.detectSource,
|
|
24
|
+
extractExtension: () => import_extractExtension.extractExtension,
|
|
24
25
|
isGifImage: () => import_isGifImage.isGifImage,
|
|
25
26
|
isImage: () => import_isImage.isImage,
|
|
26
27
|
isJpgImage: () => import_isJpgImage.isJpgImage,
|
|
@@ -29,6 +30,7 @@ __export(ImageUtils_exports, {
|
|
|
29
30
|
module.exports = __toCommonJS(ImageUtils_exports);
|
|
30
31
|
var import_detectDimension = require("./detectDimension");
|
|
31
32
|
var import_detectSource = require("./detectSource");
|
|
33
|
+
var import_extractExtension = require("./extractExtension");
|
|
32
34
|
var import_isImage = require("./isImage");
|
|
33
35
|
var import_isGifImage = require("./isGifImage");
|
|
34
36
|
var import_isJpgImage = require("./isJpgImage");
|
|
@@ -37,6 +39,7 @@ var import_isPngImage = require("./isPngImage");
|
|
|
37
39
|
0 && (module.exports = {
|
|
38
40
|
detectDimension,
|
|
39
41
|
detectSource,
|
|
42
|
+
extractExtension,
|
|
40
43
|
isGifImage,
|
|
41
44
|
isImage,
|
|
42
45
|
isJpgImage,
|
|
@@ -8,6 +8,7 @@ export { isAlphanumeric } from './isAlphanumeric';
|
|
|
8
8
|
export { isAlphanumericLower } from './isAlphanumericLower';
|
|
9
9
|
export { isAlphanumericUpper } from './isAlphanumericUpper';
|
|
10
10
|
export { isCompilable } from './isCompilable';
|
|
11
|
+
export { isEmail } from './isEmail';
|
|
11
12
|
export { isNumeric } from './isNumeric';
|
|
12
13
|
export { normalizePattern } from './normalizePattern';
|
|
13
14
|
export { testResetting } from './testResetting';
|
|
@@ -29,6 +29,7 @@ __export(RegexUtils_exports, {
|
|
|
29
29
|
isAlphanumericLower: () => import_isAlphanumericLower.isAlphanumericLower,
|
|
30
30
|
isAlphanumericUpper: () => import_isAlphanumericUpper.isAlphanumericUpper,
|
|
31
31
|
isCompilable: () => import_isCompilable.isCompilable,
|
|
32
|
+
isEmail: () => import_isEmail.isEmail,
|
|
32
33
|
isNumeric: () => import_isNumeric.isNumeric,
|
|
33
34
|
normalizePattern: () => import_normalizePattern.normalizePattern,
|
|
34
35
|
testResetting: () => import_testResetting.testResetting,
|
|
@@ -45,6 +46,7 @@ var import_isAlphanumeric = require("./isAlphanumeric");
|
|
|
45
46
|
var import_isAlphanumericLower = require("./isAlphanumericLower");
|
|
46
47
|
var import_isAlphanumericUpper = require("./isAlphanumericUpper");
|
|
47
48
|
var import_isCompilable = require("./isCompilable");
|
|
49
|
+
var import_isEmail = require("./isEmail");
|
|
48
50
|
var import_isNumeric = require("./isNumeric");
|
|
49
51
|
var import_normalizePattern = require("./normalizePattern");
|
|
50
52
|
var import_testResetting = require("./testResetting");
|
|
@@ -61,6 +63,7 @@ var import_unescapePattern = require("./unescapePattern");
|
|
|
61
63
|
isAlphanumericLower,
|
|
62
64
|
isAlphanumericUpper,
|
|
63
65
|
isCompilable,
|
|
66
|
+
isEmail,
|
|
64
67
|
isNumeric,
|
|
65
68
|
normalizePattern,
|
|
66
69
|
testResetting,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isEmail(text?: string | null): boolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
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/isEmail.ts
|
|
20
|
+
var isEmail_exports = {};
|
|
21
|
+
__export(isEmail_exports, {
|
|
22
|
+
isEmail: () => isEmail
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(isEmail_exports);
|
|
25
|
+
function isEmail(text) {
|
|
26
|
+
return !!text && /^[A-Za-z0-9._%+-]+@[-A-Za-z0-9.]+\.[A-Za-z]{2,}$/.test(text);
|
|
27
|
+
}
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
isEmail
|
|
31
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function extractExtension(imageSource?: string | null, allowedExtensions?: Array<string | null | undefined>, fallback?: string): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isHttp } from "../UriUtils";
|
|
2
|
+
import { isHttps } from "../UriUtils";
|
|
3
|
+
var DEFAULT_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.gif', '.webp', '.bmp', '.heic', '.heif', '.svg'];
|
|
4
|
+
export function extractExtension(imageSource) {
|
|
5
|
+
var allowedExtensions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_EXTENSIONS;
|
|
6
|
+
var fallback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.jpg';
|
|
7
|
+
if (!imageSource) {
|
|
8
|
+
return fallback;
|
|
9
|
+
}
|
|
10
|
+
var pathOnly = imageSource;
|
|
11
|
+
if (isHttp(imageSource) || isHttps(imageSource)) {
|
|
12
|
+
var qIndex = pathOnly.indexOf('?');
|
|
13
|
+
var hIndex = pathOnly.indexOf('#');
|
|
14
|
+
var cutoff = pathOnly.length;
|
|
15
|
+
if (qIndex !== -1) {
|
|
16
|
+
cutoff = Math.min(cutoff, qIndex);
|
|
17
|
+
}
|
|
18
|
+
if (hIndex !== -1) {
|
|
19
|
+
cutoff = Math.min(cutoff, hIndex);
|
|
20
|
+
}
|
|
21
|
+
pathOnly = pathOnly.substring(0, cutoff);
|
|
22
|
+
}
|
|
23
|
+
var lastDot = pathOnly.lastIndexOf('.');
|
|
24
|
+
if (lastDot === -1) {
|
|
25
|
+
return fallback;
|
|
26
|
+
}
|
|
27
|
+
var ext = pathOnly.substring(lastDot).toLowerCase();
|
|
28
|
+
if (ext === '.') {
|
|
29
|
+
return fallback;
|
|
30
|
+
}
|
|
31
|
+
if (allowedExtensions && allowedExtensions.length) {
|
|
32
|
+
var lowerExtensions = allowedExtensions.map(function (e) {
|
|
33
|
+
return e === null || e === void 0 ? void 0 : e.toLowerCase();
|
|
34
|
+
});
|
|
35
|
+
return lowerExtensions.includes(ext) ? ext : fallback;
|
|
36
|
+
}
|
|
37
|
+
return ext;
|
|
38
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { detectDimension } from './detectDimension';
|
|
2
2
|
export { detectSource } from './detectSource';
|
|
3
|
+
export { extractExtension } from './extractExtension';
|
|
3
4
|
export { isImage } from './isImage';
|
|
4
5
|
export { isGifImage } from './isGifImage';
|
|
5
6
|
export { isJpgImage } from './isJpgImage';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { detectDimension } from "./detectDimension";
|
|
2
2
|
export { detectSource } from "./detectSource";
|
|
3
|
+
export { extractExtension } from "./extractExtension";
|
|
3
4
|
export { isImage } from "./isImage";
|
|
4
5
|
export { isGifImage } from "./isGifImage";
|
|
5
6
|
export { isJpgImage } from "./isJpgImage";
|
|
@@ -8,6 +8,7 @@ export { isAlphanumeric } from './isAlphanumeric';
|
|
|
8
8
|
export { isAlphanumericLower } from './isAlphanumericLower';
|
|
9
9
|
export { isAlphanumericUpper } from './isAlphanumericUpper';
|
|
10
10
|
export { isCompilable } from './isCompilable';
|
|
11
|
+
export { isEmail } from './isEmail';
|
|
11
12
|
export { isNumeric } from './isNumeric';
|
|
12
13
|
export { normalizePattern } from './normalizePattern';
|
|
13
14
|
export { testResetting } from './testResetting';
|
|
@@ -8,6 +8,7 @@ export { isAlphanumeric } from "./isAlphanumeric";
|
|
|
8
8
|
export { isAlphanumericLower } from "./isAlphanumericLower";
|
|
9
9
|
export { isAlphanumericUpper } from "./isAlphanumericUpper";
|
|
10
10
|
export { isCompilable } from "./isCompilable";
|
|
11
|
+
export { isEmail } from "./isEmail";
|
|
11
12
|
export { isNumeric } from "./isNumeric";
|
|
12
13
|
export { normalizePattern } from "./normalizePattern";
|
|
13
14
|
export { testResetting } from "./testResetting";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isEmail(text?: string | null): boolean;
|
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.10",
|
|
4
4
|
"title": "TsLangUtils",
|
|
5
5
|
"description": "Common lang utilities for typescript",
|
|
6
6
|
"homepage": "https://unikueltd.github.io/ts-lang-utils",
|
|
@@ -68,14 +68,15 @@
|
|
|
68
68
|
"@unikue/typedoc-theme-dumi": "^1.1.3",
|
|
69
69
|
"del-cli": "^7.0.0",
|
|
70
70
|
"eslint": "^10.6.0",
|
|
71
|
-
"eslint-plugin-jest": "^29.15.
|
|
72
|
-
"father": "^4.6.
|
|
71
|
+
"eslint-plugin-jest": "^29.15.4",
|
|
72
|
+
"father": "^4.6.25",
|
|
73
73
|
"gh-pages": "^6.3.0",
|
|
74
74
|
"globals": "^17.7.0",
|
|
75
|
+
"jest-environment-jsdom": "^30.4.1",
|
|
75
76
|
"ts-jest": "^29.4.11",
|
|
76
77
|
"typedoc": "~0.28.19",
|
|
77
78
|
"typescript": "^6.0.3",
|
|
78
|
-
"typescript-eslint": "^8.62.
|
|
79
|
+
"typescript-eslint": "^8.62.1"
|
|
79
80
|
},
|
|
80
81
|
"peerDependencies": {
|
|
81
82
|
"typescript": ">=4.0.0"
|