zavadil-ts-common 1.2.69 → 1.2.71
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/index.d.ts +1 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/util/StringUtil.d.ts +1 -0
- package/dist/util/UrlUtil.d.ts +1 -0
- package/package.json +1 -1
- package/src/util/StringUtil.ts +12 -13
- package/src/util/UrlUtil.ts +5 -0
package/dist/util/UrlUtil.d.ts
CHANGED
@@ -2,4 +2,5 @@ export default class UrlUtil {
|
|
2
2
|
static deleteParamFromUrl(url: string, paramName: string): string;
|
3
3
|
static extractParamFromUrl(url: string, name: string): string | null;
|
4
4
|
static paramExistsInUrl(url: string, name: string): boolean;
|
5
|
+
static extractHostFromUrl(url: string): string | null;
|
5
6
|
}
|
package/package.json
CHANGED
package/src/util/StringUtil.ts
CHANGED
@@ -2,8 +2,12 @@ import {ObjectUtil} from "./ObjectUtil";
|
|
2
2
|
|
3
3
|
export class StringUtil {
|
4
4
|
|
5
|
+
static isString(s: any): boolean {
|
6
|
+
return typeof s === 'string';
|
7
|
+
}
|
8
|
+
|
5
9
|
static toString(s: any): string {
|
6
|
-
return
|
10
|
+
return StringUtil.isString(s) ? s : s?.toString?.() ?? '';
|
7
11
|
}
|
8
12
|
|
9
13
|
static isEmpty(str: string | null | undefined): str is null | undefined {
|
@@ -42,27 +46,22 @@ export class StringUtil {
|
|
42
46
|
|
43
47
|
static trimLeadingSlashes(str: string | null): string {
|
44
48
|
if (this.isEmpty(str)) return '';
|
45
|
-
|
46
|
-
// @ts-ignore
|
47
|
-
return str.replace(/^\//g, '');
|
49
|
+
return StringUtil.toString(str).replace(/^\//g, '');
|
48
50
|
}
|
49
51
|
|
50
52
|
static trimTrailingSlashes(str: string | null): string {
|
51
53
|
if (this.isEmpty(str)) return '';
|
52
|
-
|
53
|
-
// @ts-ignore
|
54
|
-
return str.replace(/\/$/g, '');
|
54
|
+
return StringUtil.toString(str).replace(/\/$/g, '');
|
55
55
|
}
|
56
56
|
|
57
57
|
static trimSlashes(str: string | null): string {
|
58
58
|
if (this.isEmpty(str)) return '';
|
59
|
-
|
60
|
-
// @ts-ignore
|
61
|
-
return str.replace(/^\/|\/$/g, '');
|
59
|
+
return StringUtil.toString(str).replace(/^\/|\/$/g, '');
|
62
60
|
}
|
63
61
|
|
64
62
|
static safeTruncate(str: string | null | undefined, len: number, ellipsis: string = ''): string {
|
65
63
|
if (StringUtil.isEmpty(str) || !str) return '';
|
64
|
+
str = StringUtil.toString(str);
|
66
65
|
if (str.length <= len) return String(str);
|
67
66
|
return str.substring(0, len - ellipsis.length) + ellipsis;
|
68
67
|
}
|
@@ -73,17 +72,17 @@ export class StringUtil {
|
|
73
72
|
|
74
73
|
static safeTrim(str: string | null | undefined): string {
|
75
74
|
if (StringUtil.isEmpty(str)) return '';
|
76
|
-
return str.trim();
|
75
|
+
return StringUtil.toString(str).trim();
|
77
76
|
}
|
78
77
|
|
79
78
|
static safeLowercase(str: string | null | undefined): string {
|
80
79
|
if (StringUtil.isEmpty(str) || !str) return '';
|
81
|
-
return str.toLowerCase();
|
80
|
+
return StringUtil.toString(str).toLowerCase();
|
82
81
|
}
|
83
82
|
|
84
83
|
static safeUppercase(str: string | null | undefined): string {
|
85
84
|
if (StringUtil.isEmpty(str) || !str) return '';
|
86
|
-
return str.toUpperCase();
|
85
|
+
return StringUtil.toString(str).toUpperCase();
|
87
86
|
}
|
88
87
|
|
89
88
|
static toBigInt(str: string | null): bigint | null {
|
package/src/util/UrlUtil.ts
CHANGED
@@ -16,4 +16,9 @@ export default class UrlUtil {
|
|
16
16
|
static paramExistsInUrl(url: string, name: string): boolean {
|
17
17
|
return StringUtil.notBlank(UrlUtil.extractParamFromUrl(url, name));
|
18
18
|
}
|
19
|
+
static extractHostFromUrl(url: string): string | null {
|
20
|
+
if (StringUtil.isBlank(url)) return null;
|
21
|
+
return new URL(url).host;
|
22
|
+
}
|
23
|
+
|
19
24
|
}
|