@bgord/tools 0.4.0 → 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.
@@ -0,0 +1,3 @@
1
+ import { z } from "zod/v4";
2
+ export declare const ApiKey: z.ZodString;
3
+ export type ApiKeyType = z.infer<typeof ApiKey>;
@@ -0,0 +1,2 @@
1
+ import { z } from "zod/v4";
2
+ export const ApiKey = z.string().trim().length(64);
@@ -0,0 +1,3 @@
1
+ import { z } from "zod/v4";
2
+ export declare const BuildVersion: z.ZodString;
3
+ export type BuildVersionType = z.infer<typeof BuildVersion>;
@@ -0,0 +1,2 @@
1
+ import { z } from "zod/v4";
2
+ export const BuildVersion = z.string().min(1).max(8);
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,3 @@
1
+ import { z } from "zod/v4";
2
+ export declare const Language: z.ZodString;
3
+ export type LanguageType = z.infer<typeof Language>;
@@ -0,0 +1,5 @@
1
+ import { z } from "zod/v4";
2
+ export const Language = z
3
+ .string()
4
+ .length(2)
5
+ .regex(/^[a-z]{2}$/, { message: "invalid_language" });
@@ -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
+ }
@@ -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>;
@@ -0,0 +1,7 @@
1
+ import { z } from "zod/v4";
2
+ export const TimeZoneOffsetValue = z
3
+ .string()
4
+ .trim()
5
+ .or(z.undefined())
6
+ .transform((value) => Number(value))
7
+ .transform((value) => (Number.isNaN(value) ? 0 : value));
@@ -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;
@@ -1,6 +1,6 @@
1
1
  import { RoundToDecimal } from "./rounding.service";
2
2
  const rounding = new RoundToDecimal(2);
3
- class TimeResult {
3
+ export class TimeResult {
4
4
  constructor(days, hours, minutes, seconds, ms) {
5
5
  this.days = days;
6
6
  this.hours = hours;
@@ -0,0 +1,3 @@
1
+ import { z } from "zod/v4";
2
+ export declare const Timezone: z.ZodString;
3
+ export type TimezoneType = z.infer<typeof Timezone>;
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/tools",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Bartosz Gordon",
@@ -0,0 +1,4 @@
1
+ import { z } from "zod/v4";
2
+
3
+ export const ApiKey = z.string().trim().length(64);
4
+ export type ApiKeyType = z.infer<typeof ApiKey>;
@@ -0,0 +1,5 @@
1
+ import { z } from "zod/v4";
2
+
3
+ export const BuildVersion = z.string().min(1).max(8);
4
+
5
+ export type BuildVersionType = z.infer<typeof BuildVersion>;
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,8 @@
1
+ import { z } from "zod/v4";
2
+
3
+ export const Language = z
4
+ .string()
5
+ .length(2)
6
+ .regex(/^[a-z]{2}$/, { message: "invalid_language" });
7
+
8
+ export type LanguageType = z.infer<typeof Language>;
@@ -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>;
@@ -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>;