@bgord/tools 0.3.1 → 0.5.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/dist/api-key.vo.d.ts +3 -0
- package/dist/api-key.vo.js +2 -0
- package/dist/build-version.vo.d.ts +3 -0
- package/dist/build-version.vo.js +2 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/language.vo.d.ts +3 -0
- package/dist/language.vo.js +5 -0
- package/dist/package-version.vo.d.ts +20 -0
- package/dist/package-version.vo.js +69 -0
- package/dist/size.vo.d.ts +1 -1
- package/dist/stopwatch.service.d.ts +1 -2
- package/dist/time-zone-offset-value.vo.d.ts +3 -0
- package/dist/time-zone-offset-value.vo.js +7 -0
- package/dist/time.service.d.ts +10 -0
- package/dist/time.service.js +1 -1
- package/dist/timezone.vo.d.ts +3 -0
- package/dist/timezone.vo.js +19 -0
- package/package.json +1 -1
- package/src/api-key.vo.ts +4 -0
- package/src/build-version.vo.ts +5 -0
- package/src/index.ts +6 -0
- package/src/language.vo.ts +8 -0
- package/src/package-version.vo.ts +92 -0
- package/src/time-zone-offset-value.vo.ts +10 -0
- package/src/time.service.ts +1 -1
- package/src/timezone.vo.ts +26 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
+
export * from "./api-key.vo";
|
|
2
|
+
export * from "./build-version.vo";
|
|
1
3
|
export * from "./date-calculator.service";
|
|
2
4
|
export * from "./date-formatter.service";
|
|
3
5
|
export * from "./dates-of-the-week.vo";
|
|
4
6
|
export * from "./etags.vo";
|
|
7
|
+
export * from "./language.vo";
|
|
5
8
|
export * from "./mime.vo";
|
|
6
9
|
export * from "./noop.service";
|
|
10
|
+
export * from "./package-version.vo";
|
|
7
11
|
export * from "./rate-limiter.service";
|
|
8
12
|
export * from "./relative-date.vo";
|
|
9
13
|
export * from "./rounding.service";
|
|
10
14
|
export * from "./size.vo";
|
|
11
15
|
export * from "./sleep.service";
|
|
12
16
|
export * from "./stopwatch.service";
|
|
17
|
+
export * from "./time-zone-offset-value.vo";
|
|
13
18
|
export * from "./time.service";
|
|
14
19
|
export * from "./timestamp.vo";
|
|
20
|
+
export * from "./timezone.vo";
|
|
15
21
|
export * from "./ts-utils";
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
+
export * from "./api-key.vo";
|
|
2
|
+
export * from "./build-version.vo";
|
|
1
3
|
export * from "./date-calculator.service";
|
|
2
4
|
export * from "./date-formatter.service";
|
|
3
5
|
export * from "./dates-of-the-week.vo";
|
|
4
6
|
export * from "./etags.vo";
|
|
7
|
+
export * from "./language.vo";
|
|
5
8
|
export * from "./mime.vo";
|
|
6
9
|
export * from "./noop.service";
|
|
10
|
+
export * from "./package-version.vo";
|
|
7
11
|
export * from "./rate-limiter.service";
|
|
8
12
|
export * from "./relative-date.vo";
|
|
9
13
|
export * from "./rounding.service";
|
|
10
14
|
export * from "./size.vo";
|
|
11
15
|
export * from "./sleep.service";
|
|
12
16
|
export * from "./stopwatch.service";
|
|
17
|
+
export * from "./time-zone-offset-value.vo";
|
|
13
18
|
export * from "./time.service";
|
|
14
19
|
export * from "./timestamp.vo";
|
|
20
|
+
export * from "./timezone.vo";
|
|
15
21
|
export * from "./ts-utils";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
type MajorType = number;
|
|
3
|
+
type MinorType = number;
|
|
4
|
+
type PatchType = number;
|
|
5
|
+
export declare const PackageVersionSchema: z.ZodPipe<z.ZodString, z.ZodTransform<{
|
|
6
|
+
major: number;
|
|
7
|
+
minor: number;
|
|
8
|
+
patch: number;
|
|
9
|
+
}, string>>;
|
|
10
|
+
export type PackageVersionSchemaType = z.infer<typeof PackageVersionSchema>;
|
|
11
|
+
export declare class PackageVersion {
|
|
12
|
+
readonly major: MajorType;
|
|
13
|
+
readonly minor: MinorType;
|
|
14
|
+
readonly patch: PatchType;
|
|
15
|
+
constructor(major: MajorType, minor: MinorType, patch: PatchType);
|
|
16
|
+
isGreaterThanOrEqual(another: PackageVersion): boolean;
|
|
17
|
+
static fromStringWithV(value: string): PackageVersion;
|
|
18
|
+
static fromString(value: string): PackageVersion;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export const PackageVersionSchema = z
|
|
3
|
+
.string()
|
|
4
|
+
.min(1)
|
|
5
|
+
.refine((value) => {
|
|
6
|
+
try {
|
|
7
|
+
if (!value.startsWith("v"))
|
|
8
|
+
return false;
|
|
9
|
+
const [, version] = value.split("v");
|
|
10
|
+
if (!version)
|
|
11
|
+
return false;
|
|
12
|
+
const [major, minor, patch] = version.split(".");
|
|
13
|
+
if (!(major && minor && patch))
|
|
14
|
+
return false;
|
|
15
|
+
if (!(Number.isInteger(Number(major)) &&
|
|
16
|
+
Number.isInteger(Number(minor)) &&
|
|
17
|
+
Number.isInteger(Number(patch)))) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (!(Number.isInteger(Number(major)) &&
|
|
21
|
+
Number.isInteger(Number(minor)) &&
|
|
22
|
+
Number.isInteger(Number(patch)))) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}, { message: "package.version.error" })
|
|
31
|
+
.transform((value) => {
|
|
32
|
+
const [, version] = value.split("v");
|
|
33
|
+
const [major, minor, patch] = version.split(".");
|
|
34
|
+
return {
|
|
35
|
+
major: Number(major),
|
|
36
|
+
minor: Number(minor),
|
|
37
|
+
patch: Number(patch),
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
export class PackageVersion {
|
|
41
|
+
constructor(major, minor, patch) {
|
|
42
|
+
this.major = major;
|
|
43
|
+
this.minor = minor;
|
|
44
|
+
this.patch = patch;
|
|
45
|
+
}
|
|
46
|
+
isGreaterThanOrEqual(another) {
|
|
47
|
+
if (this.major > another.major)
|
|
48
|
+
return true;
|
|
49
|
+
if (this.major < another.major)
|
|
50
|
+
return false;
|
|
51
|
+
if (this.minor > another.minor)
|
|
52
|
+
return true;
|
|
53
|
+
if (this.minor < another.minor)
|
|
54
|
+
return false;
|
|
55
|
+
if (this.patch > another.patch)
|
|
56
|
+
return true;
|
|
57
|
+
if (this.patch < another.patch)
|
|
58
|
+
return false;
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
static fromStringWithV(value) {
|
|
62
|
+
const version = PackageVersionSchema.parse(value);
|
|
63
|
+
return new PackageVersion(version.major, version.minor, version.patch);
|
|
64
|
+
}
|
|
65
|
+
static fromString(value) {
|
|
66
|
+
const version = PackageVersionSchema.parse(`v${value}`);
|
|
67
|
+
return new PackageVersion(version.major, version.minor, version.patch);
|
|
68
|
+
}
|
|
69
|
+
}
|
package/dist/size.vo.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare enum SizeUnit {
|
|
|
6
6
|
GB = "GB"
|
|
7
7
|
}
|
|
8
8
|
declare const SizeValueSchema: z.ZodNumber;
|
|
9
|
-
type SizeValueType = z.infer<typeof SizeValueSchema>;
|
|
9
|
+
export type SizeValueType = z.infer<typeof SizeValueSchema>;
|
|
10
10
|
type SizeConfigType = {
|
|
11
11
|
unit: SizeUnit;
|
|
12
12
|
value: SizeValueType;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TimestampType } from "./timestamp.vo";
|
|
2
|
-
type StopwatchResultType = {
|
|
2
|
+
export type StopwatchResultType = {
|
|
3
3
|
durationMs: TimestampType;
|
|
4
4
|
};
|
|
5
5
|
export declare class Stopwatch {
|
|
@@ -8,4 +8,3 @@ export declare class Stopwatch {
|
|
|
8
8
|
private stopMs;
|
|
9
9
|
stop(): StopwatchResultType;
|
|
10
10
|
}
|
|
11
|
-
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export declare const TimeZoneOffsetValue: z.ZodPipe<z.ZodPipe<z.ZodUnion<[z.ZodString, z.ZodUndefined]>, z.ZodTransform<number, string | undefined>>, z.ZodTransform<number, number>>;
|
|
3
|
+
export type TimeZoneOffsetValueType = z.infer<typeof TimeZoneOffsetValue>;
|
package/dist/time.service.d.ts
CHANGED
|
@@ -7,6 +7,16 @@ interface TimeResultInterface {
|
|
|
7
7
|
isAfter(another: TimeResultInterface): boolean;
|
|
8
8
|
isBefore(another: TimeResultInterface): boolean;
|
|
9
9
|
}
|
|
10
|
+
export declare class TimeResult implements TimeResultInterface {
|
|
11
|
+
readonly days: number;
|
|
12
|
+
readonly hours: number;
|
|
13
|
+
readonly minutes: number;
|
|
14
|
+
readonly seconds: number;
|
|
15
|
+
readonly ms: number;
|
|
16
|
+
constructor(days: number, hours: number, minutes: number, seconds: number, ms: number);
|
|
17
|
+
isAfter(another: TimeResultInterface): boolean;
|
|
18
|
+
isBefore(another: TimeResultInterface): boolean;
|
|
19
|
+
}
|
|
10
20
|
export declare class Time {
|
|
11
21
|
static Days(value: number): TimeResultInterface;
|
|
12
22
|
static Hours(value: number): TimeResultInterface;
|
package/dist/time.service.js
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export const Timezone = z
|
|
3
|
+
.string()
|
|
4
|
+
.min(1)
|
|
5
|
+
.refine((value) => {
|
|
6
|
+
try {
|
|
7
|
+
// Create a dummy date and time format using the specified timezone
|
|
8
|
+
const dummyDate = new Date();
|
|
9
|
+
const formatter = new Intl.DateTimeFormat("en-US", { timeZone: value });
|
|
10
|
+
// Format the dummy date
|
|
11
|
+
formatter.format(dummyDate);
|
|
12
|
+
// If the formatting succeeds without throwing an error, the timezone is valid
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
// An error occurred, indicating an invalid timezone
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}, { message: "timezone.invalid" });
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
+
export * from "./api-key.vo";
|
|
2
|
+
export * from "./build-version.vo";
|
|
1
3
|
export * from "./date-calculator.service";
|
|
2
4
|
export * from "./date-formatter.service";
|
|
3
5
|
export * from "./dates-of-the-week.vo";
|
|
4
6
|
export * from "./etags.vo";
|
|
7
|
+
export * from "./language.vo";
|
|
5
8
|
export * from "./mime.vo";
|
|
6
9
|
export * from "./noop.service";
|
|
10
|
+
export * from "./package-version.vo";
|
|
7
11
|
export * from "./rate-limiter.service";
|
|
8
12
|
export * from "./relative-date.vo";
|
|
9
13
|
export * from "./rounding.service";
|
|
10
14
|
export * from "./size.vo";
|
|
11
15
|
export * from "./sleep.service";
|
|
12
16
|
export * from "./stopwatch.service";
|
|
17
|
+
export * from "./time-zone-offset-value.vo";
|
|
13
18
|
export * from "./time.service";
|
|
14
19
|
export * from "./timestamp.vo";
|
|
20
|
+
export * from "./timezone.vo";
|
|
15
21
|
export * from "./ts-utils";
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
type MajorType = number;
|
|
4
|
+
type MinorType = number;
|
|
5
|
+
type PatchType = number;
|
|
6
|
+
|
|
7
|
+
export const PackageVersionSchema = z
|
|
8
|
+
.string()
|
|
9
|
+
.min(1)
|
|
10
|
+
.refine(
|
|
11
|
+
(value) => {
|
|
12
|
+
try {
|
|
13
|
+
if (!value.startsWith("v")) return false;
|
|
14
|
+
|
|
15
|
+
const [, version] = value.split("v");
|
|
16
|
+
if (!version) return false;
|
|
17
|
+
|
|
18
|
+
const [major, minor, patch] = version.split(".");
|
|
19
|
+
if (!(major && minor && patch)) return false;
|
|
20
|
+
|
|
21
|
+
if (
|
|
22
|
+
!(
|
|
23
|
+
Number.isInteger(Number(major)) &&
|
|
24
|
+
Number.isInteger(Number(minor)) &&
|
|
25
|
+
Number.isInteger(Number(patch))
|
|
26
|
+
)
|
|
27
|
+
) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (
|
|
32
|
+
!(
|
|
33
|
+
Number.isInteger(Number(major)) &&
|
|
34
|
+
Number.isInteger(Number(minor)) &&
|
|
35
|
+
Number.isInteger(Number(patch))
|
|
36
|
+
)
|
|
37
|
+
) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return true;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{ message: "package.version.error" },
|
|
47
|
+
)
|
|
48
|
+
.transform((value) => {
|
|
49
|
+
const [, version] = value.split("v");
|
|
50
|
+
|
|
51
|
+
const [major, minor, patch] = (version as string).split(".");
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
major: Number(major),
|
|
55
|
+
minor: Number(minor),
|
|
56
|
+
patch: Number(patch),
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
export type PackageVersionSchemaType = z.infer<typeof PackageVersionSchema>;
|
|
60
|
+
|
|
61
|
+
export class PackageVersion {
|
|
62
|
+
constructor(
|
|
63
|
+
readonly major: MajorType,
|
|
64
|
+
readonly minor: MinorType,
|
|
65
|
+
readonly patch: PatchType,
|
|
66
|
+
) {}
|
|
67
|
+
|
|
68
|
+
isGreaterThanOrEqual(another: PackageVersion) {
|
|
69
|
+
if (this.major > another.major) return true;
|
|
70
|
+
if (this.major < another.major) return false;
|
|
71
|
+
|
|
72
|
+
if (this.minor > another.minor) return true;
|
|
73
|
+
if (this.minor < another.minor) return false;
|
|
74
|
+
|
|
75
|
+
if (this.patch > another.patch) return true;
|
|
76
|
+
if (this.patch < another.patch) return false;
|
|
77
|
+
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static fromStringWithV(value: string) {
|
|
82
|
+
const version = PackageVersionSchema.parse(value);
|
|
83
|
+
|
|
84
|
+
return new PackageVersion(version.major, version.minor, version.patch);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static fromString(value: string) {
|
|
88
|
+
const version = PackageVersionSchema.parse(`v${value}`);
|
|
89
|
+
|
|
90
|
+
return new PackageVersion(version.major, version.minor, version.patch);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
export const TimeZoneOffsetValue = z
|
|
4
|
+
.string()
|
|
5
|
+
.trim()
|
|
6
|
+
.or(z.undefined())
|
|
7
|
+
.transform((value) => Number(value))
|
|
8
|
+
.transform((value) => (Number.isNaN(value) ? 0 : value));
|
|
9
|
+
|
|
10
|
+
export type TimeZoneOffsetValueType = z.infer<typeof TimeZoneOffsetValue>;
|
package/src/time.service.ts
CHANGED
|
@@ -13,7 +13,7 @@ interface TimeResultInterface {
|
|
|
13
13
|
isBefore(another: TimeResultInterface): boolean;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
class TimeResult implements TimeResultInterface {
|
|
16
|
+
export class TimeResult implements TimeResultInterface {
|
|
17
17
|
constructor(
|
|
18
18
|
readonly days: number,
|
|
19
19
|
readonly hours: number,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
export const Timezone = z
|
|
4
|
+
.string()
|
|
5
|
+
.min(1)
|
|
6
|
+
.refine(
|
|
7
|
+
(value) => {
|
|
8
|
+
try {
|
|
9
|
+
// Create a dummy date and time format using the specified timezone
|
|
10
|
+
const dummyDate = new Date();
|
|
11
|
+
const formatter = new Intl.DateTimeFormat("en-US", { timeZone: value });
|
|
12
|
+
|
|
13
|
+
// Format the dummy date
|
|
14
|
+
formatter.format(dummyDate);
|
|
15
|
+
|
|
16
|
+
// If the formatting succeeds without throwing an error, the timezone is valid
|
|
17
|
+
return true;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
// An error occurred, indicating an invalid timezone
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
{ message: "timezone.invalid" },
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export type TimezoneType = z.infer<typeof Timezone>;
|