zavadil-ts-common 2.2.4 → 2.2.6
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 +9 -3
- 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/ArrayUtil.d.ts +1 -1
- package/dist/util/DateUtilCs.d.ts +4 -0
- package/dist/util/StringUtil.d.ts +1 -1
- package/dist/util/UrlUtil.d.ts +1 -0
- package/dist/util/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/util/ArrayUtil.ts +2 -4
- package/src/util/DateUtilCs.ts +28 -0
- package/src/util/StringUtil.ts +2 -2
- package/src/util/UrlUtil.ts +12 -0
- package/src/util/index.ts +1 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {DateUtil} from "./DateUtil";
|
|
2
|
+
|
|
3
|
+
export class DateUtilCs {
|
|
4
|
+
|
|
5
|
+
static formatDateForHumans(d: Date | string | null | undefined, showTime: boolean = false): string {
|
|
6
|
+
d = DateUtil.parseDate(d);
|
|
7
|
+
if (!d) return '';
|
|
8
|
+
|
|
9
|
+
const year = d.getFullYear();
|
|
10
|
+
const month = DateUtil.formatNumber(d.getMonth() + 1);
|
|
11
|
+
const day = DateUtil.formatNumber(d.getDate());
|
|
12
|
+
|
|
13
|
+
const date = `${day}.${month}.${year}`;
|
|
14
|
+
|
|
15
|
+
if (!showTime) {
|
|
16
|
+
return date;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const hours = DateUtil.formatNumber(d.getHours());
|
|
20
|
+
const minutes = DateUtil.formatNumber(d.getMinutes());
|
|
21
|
+
const seconds = DateUtil.formatNumber(d.getSeconds());
|
|
22
|
+
return `${date} ${hours}:${minutes}:${seconds}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static formatDateTimeForHumans(d: Date | string | null | undefined): string {
|
|
26
|
+
return DateUtilCs.formatDateForHumans(d, true);
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/util/StringUtil.ts
CHANGED
|
@@ -2,8 +2,8 @@ import {HashUtil} from "./HashUtil";
|
|
|
2
2
|
import {ObjectUtil} from "./ObjectUtil";
|
|
3
3
|
|
|
4
4
|
export class StringUtil {
|
|
5
|
-
static isString(
|
|
6
|
-
return typeof
|
|
5
|
+
static isString(str: any): str is string {
|
|
6
|
+
return typeof str === "string";
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
static toString(s: any): string {
|
package/src/util/UrlUtil.ts
CHANGED
|
@@ -27,4 +27,16 @@ export class UrlUtil {
|
|
|
27
27
|
if (StringUtil.isBlank(host)) return null;
|
|
28
28
|
return host.split('.').slice(-2).join('.');
|
|
29
29
|
}
|
|
30
|
+
|
|
31
|
+
static slugify(text: string): string {
|
|
32
|
+
if (StringUtil.isBlank(text)) return '';
|
|
33
|
+
return text
|
|
34
|
+
.normalize('NFKD') // split accented characters into base + diacritic
|
|
35
|
+
.replace(/[\u0300-\u036f]/g, '') // remove diacritics
|
|
36
|
+
.toLowerCase()
|
|
37
|
+
.trim()
|
|
38
|
+
.replace(/[^a-z0-9\s-]/g, '') // remove non-alphanumeric chars
|
|
39
|
+
.replace(/[\s_-]+/g, '-') // collapse whitespace/underscores/dashes into one dash
|
|
40
|
+
.replace(/^-+|-+$/g, ''); // trim leading/trailing dashes
|
|
41
|
+
}
|
|
30
42
|
}
|
package/src/util/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { AsyncUtil } from './AsyncUtil';
|
|
|
5
5
|
export { ByteUtil } from './ByteUtil';
|
|
6
6
|
export { PagingUtil } from './PagingUtil';
|
|
7
7
|
export { DateUtil } from './DateUtil';
|
|
8
|
+
export { DateUtilCs } from './DateUtilCs';
|
|
8
9
|
export { NumberUtil } from './NumberUtil';
|
|
9
10
|
export { JsonUtil } from './JsonUtil';
|
|
10
11
|
export { HashUtil } from './HashUtil';
|