@unikue/ts-lang-utils 1.2.3 → 1.2.5
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/ArrayUtils/index.d.ts +1 -0
- package/dist/cjs/util/ArrayUtils/index.js +3 -0
- package/dist/cjs/util/ArrayUtils/normalize.d.ts +1 -0
- package/dist/cjs/util/ArrayUtils/normalize.js +34 -0
- package/dist/cjs/util/DateUtils/formatDateTime.d.ts +1 -1
- package/dist/cjs/util/DateUtils/getEndOfDay.d.ts +1 -1
- package/dist/cjs/util/DateUtils/getEndOfMonth.d.ts +1 -1
- package/dist/cjs/util/DateUtils/getEndOfYear.d.ts +1 -1
- package/dist/cjs/util/DateUtils/getStartOfDay.d.ts +1 -1
- package/dist/cjs/util/DateUtils/getStartOfMonth.d.ts +1 -1
- package/dist/cjs/util/DateUtils/getStartOfYear.d.ts +1 -1
- package/dist/cjs/util/DateUtils/isTomorrow.d.ts +1 -1
- package/dist/cjs/util/DateUtils/isWeekend.d.ts +1 -1
- package/dist/cjs/util/DateUtils/isYesterday.d.ts +1 -1
- package/dist/cjs/util/DurationUtils/formatSeconds.d.ts +1 -0
- package/dist/cjs/util/DurationUtils/formatSeconds.js +44 -0
- package/dist/cjs/util/DurationUtils/index.d.ts +1 -0
- package/dist/cjs/util/DurationUtils/index.js +3 -0
- package/dist/cjs/util/DurationUtils/parseToMonths.js +1 -1
- package/dist/cjs/util/DurationUtils/parseToWeeks.js +1 -1
- package/dist/cjs/util/DurationUtils/parseToYears.js +1 -1
- package/dist/esm/util/ArrayUtils/index.d.ts +1 -0
- package/dist/esm/util/ArrayUtils/index.js +1 -0
- package/dist/esm/util/ArrayUtils/normalize.d.ts +1 -0
- package/dist/esm/util/ArrayUtils/normalize.js +6 -0
- package/dist/esm/util/DateUtils/formatDateTime.d.ts +1 -1
- package/dist/esm/util/DateUtils/getEndOfDay.d.ts +1 -1
- package/dist/esm/util/DateUtils/getEndOfMonth.d.ts +1 -1
- package/dist/esm/util/DateUtils/getEndOfYear.d.ts +1 -1
- package/dist/esm/util/DateUtils/getStartOfDay.d.ts +1 -1
- package/dist/esm/util/DateUtils/getStartOfMonth.d.ts +1 -1
- package/dist/esm/util/DateUtils/getStartOfYear.d.ts +1 -1
- package/dist/esm/util/DateUtils/isTomorrow.d.ts +1 -1
- package/dist/esm/util/DateUtils/isWeekend.d.ts +1 -1
- package/dist/esm/util/DateUtils/isYesterday.d.ts +1 -1
- package/dist/esm/util/DurationUtils/formatSeconds.d.ts +1 -0
- package/dist/esm/util/DurationUtils/formatSeconds.js +19 -0
- package/dist/esm/util/DurationUtils/index.d.ts +1 -0
- package/dist/esm/util/DurationUtils/index.js +1 -0
- package/dist/esm/util/DurationUtils/parseToMonths.js +1 -1
- package/dist/esm/util/DurationUtils/parseToWeeks.js +1 -1
- package/dist/esm/util/DurationUtils/parseToYears.js +1 -1
- package/package.json +13 -12
|
@@ -22,6 +22,7 @@ export { isNotEmpty } from './isNotEmpty';
|
|
|
22
22
|
export { isTypeof } from './isTypeof';
|
|
23
23
|
export { maxLength } from './maxLength';
|
|
24
24
|
export { minLength } from './minLength';
|
|
25
|
+
export { normalize } from './normalize';
|
|
25
26
|
export { readonly } from './readonly';
|
|
26
27
|
export { remove } from './remove';
|
|
27
28
|
export { removeAll } from './removeAll';
|
|
@@ -43,6 +43,7 @@ __export(ArrayUtils_exports, {
|
|
|
43
43
|
isTypeof: () => import_isTypeof.isTypeof,
|
|
44
44
|
maxLength: () => import_maxLength.maxLength,
|
|
45
45
|
minLength: () => import_minLength.minLength,
|
|
46
|
+
normalize: () => import_normalize.normalize,
|
|
46
47
|
readonly: () => import_readonly.readonly,
|
|
47
48
|
remove: () => import_remove.remove,
|
|
48
49
|
removeAll: () => import_removeAll.removeAll,
|
|
@@ -74,6 +75,7 @@ var import_isNotEmpty = require("./isNotEmpty");
|
|
|
74
75
|
var import_isTypeof = require("./isTypeof");
|
|
75
76
|
var import_maxLength = require("./maxLength");
|
|
76
77
|
var import_minLength = require("./minLength");
|
|
78
|
+
var import_normalize = require("./normalize");
|
|
77
79
|
var import_readonly = require("./readonly");
|
|
78
80
|
var import_remove = require("./remove");
|
|
79
81
|
var import_removeAll = require("./removeAll");
|
|
@@ -105,6 +107,7 @@ var import_singleton = require("./singleton");
|
|
|
105
107
|
isTypeof,
|
|
106
108
|
maxLength,
|
|
107
109
|
minLength,
|
|
110
|
+
normalize,
|
|
108
111
|
readonly,
|
|
109
112
|
remove,
|
|
110
113
|
removeAll,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function normalize<E>(element?: E | E[] | null): E[];
|
|
@@ -0,0 +1,34 @@
|
|
|
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/ArrayUtils/normalize.ts
|
|
20
|
+
var normalize_exports = {};
|
|
21
|
+
__export(normalize_exports, {
|
|
22
|
+
normalize: () => normalize
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(normalize_exports);
|
|
25
|
+
function normalize(element) {
|
|
26
|
+
if (!element) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
return Array.isArray(element) ? element : [element];
|
|
30
|
+
}
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
normalize
|
|
34
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function formatDateTime(date?: Date, format?: string): string | undefined;
|
|
1
|
+
export declare function formatDateTime(date?: Date | null, format?: string): string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getEndOfDay(date?: Date): Date | undefined;
|
|
1
|
+
export declare function getEndOfDay(date?: Date | null): Date | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getEndOfMonth(date?: Date): Date | undefined;
|
|
1
|
+
export declare function getEndOfMonth(date?: Date | null): Date | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getEndOfYear(date?: Date): Date | undefined;
|
|
1
|
+
export declare function getEndOfYear(date?: Date | null): Date | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getStartOfDay(date?: Date): Date | undefined;
|
|
1
|
+
export declare function getStartOfDay(date?: Date | null): Date | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getStartOfMonth(date?: Date): Date | undefined;
|
|
1
|
+
export declare function getStartOfMonth(date?: Date | null): Date | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getStartOfYear(date?: Date): Date | undefined;
|
|
1
|
+
export declare function getStartOfYear(date?: Date | null): Date | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function isTomorrow(date?: Date): boolean;
|
|
1
|
+
export declare function isTomorrow(date?: Date | null): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function isWeekend(date?: Date): boolean;
|
|
1
|
+
export declare function isWeekend(date?: Date | null): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function isYesterday(date?: Date): boolean;
|
|
1
|
+
export declare function isYesterday(date?: Date | null): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatSeconds(seconds?: number | null, forceHour?: boolean): string | undefined;
|
|
@@ -0,0 +1,44 @@
|
|
|
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/DurationUtils/formatSeconds.ts
|
|
20
|
+
var formatSeconds_exports = {};
|
|
21
|
+
__export(formatSeconds_exports, {
|
|
22
|
+
formatSeconds: () => formatSeconds
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(formatSeconds_exports);
|
|
25
|
+
function formatSeconds(seconds, forceHour = false) {
|
|
26
|
+
if (seconds === void 0 || seconds === null) {
|
|
27
|
+
return void 0;
|
|
28
|
+
}
|
|
29
|
+
if (seconds < 0 || !Number.isFinite(seconds)) {
|
|
30
|
+
return forceHour ? "00:00:00" : "00:00";
|
|
31
|
+
}
|
|
32
|
+
const h = Math.floor(seconds / 3600);
|
|
33
|
+
const m = Math.floor(seconds % 3600 / 60);
|
|
34
|
+
const s = Math.floor(seconds % 60);
|
|
35
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
36
|
+
if (h > 0 || forceHour) {
|
|
37
|
+
return `${pad(h)}:${pad(m)}:${pad(s)}`;
|
|
38
|
+
}
|
|
39
|
+
return `${pad(m)}:${pad(s)}`;
|
|
40
|
+
}
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
formatSeconds
|
|
44
|
+
});
|
|
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/util/DurationUtils/index.ts
|
|
20
20
|
var DurationUtils_exports = {};
|
|
21
21
|
__export(DurationUtils_exports, {
|
|
22
|
+
formatSeconds: () => import_formatSeconds.formatSeconds,
|
|
22
23
|
parseToDays: () => import_parseToDays.parseToDays,
|
|
23
24
|
parseToHours: () => import_parseToHours.parseToHours,
|
|
24
25
|
parseToMillis: () => import_parseToMillis.parseToMillis,
|
|
@@ -29,6 +30,7 @@ __export(DurationUtils_exports, {
|
|
|
29
30
|
parseToYears: () => import_parseToYears.parseToYears
|
|
30
31
|
});
|
|
31
32
|
module.exports = __toCommonJS(DurationUtils_exports);
|
|
33
|
+
var import_formatSeconds = require("./formatSeconds");
|
|
32
34
|
var import_parseToDays = require("./parseToDays");
|
|
33
35
|
var import_parseToHours = require("./parseToHours");
|
|
34
36
|
var import_parseToMillis = require("./parseToMillis");
|
|
@@ -39,6 +41,7 @@ var import_parseToWeeks = require("./parseToWeeks");
|
|
|
39
41
|
var import_parseToYears = require("./parseToYears");
|
|
40
42
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
43
|
0 && (module.exports = {
|
|
44
|
+
formatSeconds,
|
|
42
45
|
parseToDays,
|
|
43
46
|
parseToHours,
|
|
44
47
|
parseToMillis,
|
|
@@ -28,7 +28,7 @@ function parseToMonths(duration) {
|
|
|
28
28
|
return void 0;
|
|
29
29
|
}
|
|
30
30
|
const result = (0, import_duration.parse)(duration);
|
|
31
|
-
return result === void 0 ? void 0 : result / (1e3 * 31556952 / 12);
|
|
31
|
+
return result === void 0 ? void 0 : Math.round(result / (1e3 * 31556952 / 12));
|
|
32
32
|
}
|
|
33
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
34
|
0 && (module.exports = {
|
|
@@ -28,7 +28,7 @@ function parseToWeeks(duration) {
|
|
|
28
28
|
return void 0;
|
|
29
29
|
}
|
|
30
30
|
const result = (0, import_duration.parse)(duration);
|
|
31
|
-
return result === void 0 ? void 0 : result / (1e3 * 86400 / 7);
|
|
31
|
+
return result === void 0 ? void 0 : Math.round(result / (1e3 * 86400 / 7));
|
|
32
32
|
}
|
|
33
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
34
|
0 && (module.exports = {
|
|
@@ -28,7 +28,7 @@ function parseToYears(duration) {
|
|
|
28
28
|
return void 0;
|
|
29
29
|
}
|
|
30
30
|
const result = (0, import_duration.parse)(duration);
|
|
31
|
-
return result === void 0 ? void 0 : result / (1e3 * 31556952);
|
|
31
|
+
return result === void 0 ? void 0 : Math.round(result / (1e3 * 31556952));
|
|
32
32
|
}
|
|
33
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
34
|
0 && (module.exports = {
|
|
@@ -22,6 +22,7 @@ export { isNotEmpty } from './isNotEmpty';
|
|
|
22
22
|
export { isTypeof } from './isTypeof';
|
|
23
23
|
export { maxLength } from './maxLength';
|
|
24
24
|
export { minLength } from './minLength';
|
|
25
|
+
export { normalize } from './normalize';
|
|
25
26
|
export { readonly } from './readonly';
|
|
26
27
|
export { remove } from './remove';
|
|
27
28
|
export { removeAll } from './removeAll';
|
|
@@ -22,6 +22,7 @@ export { isNotEmpty } from "./isNotEmpty";
|
|
|
22
22
|
export { isTypeof } from "./isTypeof";
|
|
23
23
|
export { maxLength } from "./maxLength";
|
|
24
24
|
export { minLength } from "./minLength";
|
|
25
|
+
export { normalize } from "./normalize";
|
|
25
26
|
export { readonly } from "./readonly";
|
|
26
27
|
export { remove } from "./remove";
|
|
27
28
|
export { removeAll } from "./removeAll";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function normalize<E>(element?: E | E[] | null): E[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function formatDateTime(date?: Date, format?: string): string | undefined;
|
|
1
|
+
export declare function formatDateTime(date?: Date | null, format?: string): string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getEndOfDay(date?: Date): Date | undefined;
|
|
1
|
+
export declare function getEndOfDay(date?: Date | null): Date | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getEndOfMonth(date?: Date): Date | undefined;
|
|
1
|
+
export declare function getEndOfMonth(date?: Date | null): Date | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getEndOfYear(date?: Date): Date | undefined;
|
|
1
|
+
export declare function getEndOfYear(date?: Date | null): Date | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getStartOfDay(date?: Date): Date | undefined;
|
|
1
|
+
export declare function getStartOfDay(date?: Date | null): Date | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getStartOfMonth(date?: Date): Date | undefined;
|
|
1
|
+
export declare function getStartOfMonth(date?: Date | null): Date | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getStartOfYear(date?: Date): Date | undefined;
|
|
1
|
+
export declare function getStartOfYear(date?: Date | null): Date | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function isTomorrow(date?: Date): boolean;
|
|
1
|
+
export declare function isTomorrow(date?: Date | null): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function isWeekend(date?: Date): boolean;
|
|
1
|
+
export declare function isWeekend(date?: Date | null): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function isYesterday(date?: Date): boolean;
|
|
1
|
+
export declare function isYesterday(date?: Date | null): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatSeconds(seconds?: number | null, forceHour?: boolean): string | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function formatSeconds(seconds) {
|
|
2
|
+
var forceHour = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
3
|
+
if (seconds === undefined || seconds === null) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
if (seconds < 0 || !Number.isFinite(seconds)) {
|
|
7
|
+
return forceHour ? '00:00:00' : '00:00';
|
|
8
|
+
}
|
|
9
|
+
var h = Math.floor(seconds / 3600);
|
|
10
|
+
var m = Math.floor(seconds % 3600 / 60);
|
|
11
|
+
var s = Math.floor(seconds % 60);
|
|
12
|
+
var pad = function pad(n) {
|
|
13
|
+
return String(n).padStart(2, '0');
|
|
14
|
+
};
|
|
15
|
+
if (h > 0 || forceHour) {
|
|
16
|
+
return "".concat(pad(h), ":").concat(pad(m), ":").concat(pad(s));
|
|
17
|
+
}
|
|
18
|
+
return "".concat(pad(m), ":").concat(pad(s));
|
|
19
|
+
}
|
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.5",
|
|
4
4
|
"title": "TsLangUtils",
|
|
5
5
|
"description": "Common lang utilities for typescript",
|
|
6
6
|
"homepage": "https://unikueltd.github.io/ts-lang-utils",
|
|
@@ -48,13 +48,14 @@
|
|
|
48
48
|
"lint": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
|
|
49
49
|
"lint:fix": "eslint --fix \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
|
|
50
50
|
"test": "jest",
|
|
51
|
-
"test:coverage": "del-cli ./coverage && jest --coverage --coverageDirectory ./coverage"
|
|
51
|
+
"test:coverage": "del-cli ./coverage && jest --coverage --coverageDirectory ./coverage",
|
|
52
|
+
"upgrade": "npx npm-check-updates --target semver -u"
|
|
52
53
|
},
|
|
53
54
|
"dependencies": {
|
|
54
|
-
"@babel/runtime": "^7.29.
|
|
55
|
+
"@babel/runtime": "^7.29.7",
|
|
55
56
|
"@imranbarbhuiya/duration": "^5.1.8",
|
|
56
57
|
"lodash": "^4.18.1",
|
|
57
|
-
"nanoid": "^3.3.
|
|
58
|
+
"nanoid": "^3.3.15",
|
|
58
59
|
"universal-cookie": "^8.1.2"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
@@ -62,19 +63,19 @@
|
|
|
62
63
|
"@eslint/js": "^10.0.1",
|
|
63
64
|
"@types/jest": "^30.0.0",
|
|
64
65
|
"@types/lodash": "^4.17.24",
|
|
65
|
-
"@unikue/babel-plugin-remove-comment": "^1.2.
|
|
66
|
-
"@unikue/typedoc-plugin-raw-content": "^1.1.
|
|
67
|
-
"@unikue/typedoc-theme-dumi": "^1.1.
|
|
66
|
+
"@unikue/babel-plugin-remove-comment": "^1.2.1",
|
|
67
|
+
"@unikue/typedoc-plugin-raw-content": "^1.1.1",
|
|
68
|
+
"@unikue/typedoc-theme-dumi": "^1.1.3",
|
|
68
69
|
"del-cli": "^7.0.0",
|
|
69
|
-
"eslint": "^10.
|
|
70
|
+
"eslint": "^10.5.0",
|
|
70
71
|
"eslint-plugin-jest": "^29.15.2",
|
|
71
|
-
"father": "^4.6.
|
|
72
|
+
"father": "^4.6.23",
|
|
72
73
|
"gh-pages": "^6.3.0",
|
|
73
|
-
"globals": "^17.
|
|
74
|
-
"ts-jest": "^29.4.
|
|
74
|
+
"globals": "^17.7.0",
|
|
75
|
+
"ts-jest": "^29.4.11",
|
|
75
76
|
"typedoc": "~0.28.19",
|
|
76
77
|
"typescript": "^6.0.3",
|
|
77
|
-
"typescript-eslint": "^8.
|
|
78
|
+
"typescript-eslint": "^8.62.0"
|
|
78
79
|
},
|
|
79
80
|
"peerDependencies": {
|
|
80
81
|
"typescript": ">=4.0.0"
|