@uxf/core 11.97.0 → 11.106.0
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/README.md +16 -0
- package/date/is-time-string.test.js +1 -1
- package/date/to-time-string.test.js +1 -1
- package/package.json +4 -1
- package/utils/ts-pattern.d.ts +1 -0
- package/utils/ts-pattern.js +9 -0
- package/date/to-date-string.d.ts +0 -5
- package/date/to-date-string.js +0 -10
- package/date/to-date-string.test.d.ts +0 -1
- package/date/to-date-string.test.js +0 -7
- package/date/to-datetime-string.d.ts +0 -5
- package/date/to-datetime-string.js +0 -20
- package/date/to-datetime-string.test.d.ts +0 -1
- package/date/to-datetime-string.test.js +0 -14
package/README.md
CHANGED
|
@@ -139,6 +139,22 @@ switch(value) {
|
|
|
139
139
|
}
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
+
### ts-pattern
|
|
143
|
+
|
|
144
|
+
Re-export of the [ts-pattern](https://github.com/gvergnaud/ts-pattern) library for exhaustive pattern matching. This provides a more powerful and type-safe alternative to switch statements with support for complex patterns, guards, and exhaustiveness checking.
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
import { match, Pattern } from "@uxf/core/utils/ts-pattern";
|
|
148
|
+
|
|
149
|
+
const result = match(value)
|
|
150
|
+
.with("a", () => "A")
|
|
151
|
+
.with("b", () => "B")
|
|
152
|
+
.with(Pattern.string, (str) => `String: ${str}`)
|
|
153
|
+
.exhaustive();
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
For full documentation, see the [official ts-pattern docs](https://github.com/gvergnaud/ts-pattern).
|
|
157
|
+
|
|
142
158
|
## assertNotNil
|
|
143
159
|
|
|
144
160
|
```tsx
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const is_time_string_1 = require("./is-time-string");
|
|
4
|
-
test("
|
|
4
|
+
test("isTimeString", () => {
|
|
5
5
|
expect((0, is_time_string_1.isTimeString)("00:00:00")).toBe(true);
|
|
6
6
|
expect((0, is_time_string_1.isTimeString)("12:30:30")).toBe(true);
|
|
7
7
|
expect((0, is_time_string_1.isTimeString)("23:59:59")).toBe(true);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const to_time_string_1 = require("./to-time-string");
|
|
4
|
-
test("
|
|
4
|
+
test("toTimeString", () => {
|
|
5
5
|
expect((0, to_time_string_1.toTimeString)(new Date("2024-01-01 01:01:01"))).toBe("01:01:01");
|
|
6
6
|
expect((0, to_time_string_1.toTimeString)(new Date("2024-01-01 20:15:30"))).toBe("20:15:30");
|
|
7
7
|
expect((0, to_time_string_1.toTimeString)(new Date("2024-01-01 23:59:59"))).toBe("23:59:59");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/core",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.106.0",
|
|
4
4
|
"description": "UXF Core",
|
|
5
5
|
"author": "Petr Vejvoda <vejvoda@uxf.cz>",
|
|
6
6
|
"homepage": "https://gitlab.com/uxf-npm/core#readme",
|
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
"build": "tsc -P tsconfig.json",
|
|
20
20
|
"typecheck": "tsc --noEmit --skipLibCheck"
|
|
21
21
|
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"ts-pattern": "5.9.0"
|
|
24
|
+
},
|
|
22
25
|
"bugs": {
|
|
23
26
|
"url": "https://gitlab.com/uxf-npm/core/issues"
|
|
24
27
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { NonExhaustiveError, P, Pattern, isMatching, match } from "ts-pattern";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.match = exports.isMatching = exports.Pattern = exports.P = exports.NonExhaustiveError = void 0;
|
|
4
|
+
var ts_pattern_1 = require("ts-pattern");
|
|
5
|
+
Object.defineProperty(exports, "NonExhaustiveError", { enumerable: true, get: function () { return ts_pattern_1.NonExhaustiveError; } });
|
|
6
|
+
Object.defineProperty(exports, "P", { enumerable: true, get: function () { return ts_pattern_1.P; } });
|
|
7
|
+
Object.defineProperty(exports, "Pattern", { enumerable: true, get: function () { return ts_pattern_1.Pattern; } });
|
|
8
|
+
Object.defineProperty(exports, "isMatching", { enumerable: true, get: function () { return ts_pattern_1.isMatching; } });
|
|
9
|
+
Object.defineProperty(exports, "match", { enumerable: true, get: function () { return ts_pattern_1.match; } });
|
package/date/to-date-string.d.ts
DELETED
package/date/to-date-string.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toDateString = toDateString;
|
|
4
|
-
const is_nil_1 = require("../utils/is-nil");
|
|
5
|
-
function toDateString(value) {
|
|
6
|
-
if ((0, is_nil_1.isNil)(value)) {
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
|
-
return value.toISOString().substring(0, 10);
|
|
10
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const to_date_string_1 = require("./to-date-string");
|
|
4
|
-
test("toDateString", () => {
|
|
5
|
-
expect((0, to_date_string_1.toDateString)(new Date("2024-10-30 12:00:00"))).toBe("2024-10-30");
|
|
6
|
-
expect((0, to_date_string_1.toDateString)(new Date("2300-01-01 12:00:00"))).toBe("2300-01-01");
|
|
7
|
-
});
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { DatetimeString } from "./index";
|
|
2
|
-
type InputType = Date | null;
|
|
3
|
-
type ReturnType<T extends InputType> = T extends null ? DatetimeString | null : DatetimeString;
|
|
4
|
-
export declare function toDatetimeString<T extends InputType>(value: T): ReturnType<T>;
|
|
5
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toDatetimeString = toDatetimeString;
|
|
4
|
-
const is_nil_1 = require("../utils/is-nil");
|
|
5
|
-
function toDatetimeString(value) {
|
|
6
|
-
if ((0, is_nil_1.isNil)(value)) {
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
|
-
const month = String(value.getMonth() + 1).padStart(2, "0");
|
|
10
|
-
const day = String(value.getDate()).padStart(2, "0");
|
|
11
|
-
const hours = String(value.getHours()).padStart(2, "0");
|
|
12
|
-
const minutes = String(value.getMinutes()).padStart(2, "0");
|
|
13
|
-
const seconds = String(value.getSeconds()).padStart(2, "0");
|
|
14
|
-
const timezoneOffset = -value.getTimezoneOffset();
|
|
15
|
-
const offsetHours = String(Math.floor(Math.abs(timezoneOffset) / 60)).padStart(2, "0");
|
|
16
|
-
const offsetMinutes = String(Math.abs(timezoneOffset) % 60).padStart(2, "0");
|
|
17
|
-
const offsetSign = timezoneOffset >= 0 ? "+" : "-";
|
|
18
|
-
const timezone = `${offsetSign}${offsetHours}:${offsetMinutes}`;
|
|
19
|
-
return `${value.getFullYear()}-${month}-${day}T${hours}:${minutes}:${seconds}${timezone}`;
|
|
20
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const to_datetime_string_1 = require("./to-datetime-string");
|
|
4
|
-
test("toDatetimeString", () => {
|
|
5
|
-
const oldTimezoneFunction = Date.prototype.getTimezoneOffset;
|
|
6
|
-
Date.prototype.getTimezoneOffset = () => -60;
|
|
7
|
-
expect((0, to_datetime_string_1.toDatetimeString)(new Date("2024-01-01 20:15:30"))).toBe("2024-01-01T20:15:30+01:00");
|
|
8
|
-
Date.prototype.getTimezoneOffset = () => -120;
|
|
9
|
-
expect((0, to_datetime_string_1.toDatetimeString)(new Date("2024-08-01 20:15:30"))).toBe("2024-08-01T20:15:30+02:00");
|
|
10
|
-
expect((0, to_datetime_string_1.toDatetimeString)(new Date("2024-08-01 23:59:59"))).toBe("2024-08-01T23:59:59+02:00");
|
|
11
|
-
Date.prototype.getTimezoneOffset = () => -150;
|
|
12
|
-
expect((0, to_datetime_string_1.toDatetimeString)(new Date("2024-01-01 12:00:00"))).toBe("2024-01-01T12:00:00+02:30");
|
|
13
|
-
Date.prototype.getTimezoneOffset = oldTimezoneFunction;
|
|
14
|
-
});
|