@bgord/tools 0.14.3 → 0.15.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/age.vo.d.ts +10 -6
- package/dist/age.vo.js +22 -14
- package/dist/api-key.vo.d.ts +3 -0
- package/dist/api-key.vo.js +7 -1
- package/dist/clock-format.service.d.ts +9 -0
- package/dist/clock-format.service.js +10 -0
- package/dist/clock.vo.d.ts +7 -14
- package/dist/clock.vo.js +25 -34
- package/dist/height.vo.d.ts +7 -7
- package/dist/height.vo.js +6 -6
- package/dist/hour-format.service.d.ts +10 -0
- package/dist/hour-format.service.js +19 -0
- package/dist/hour.vo.d.ts +8 -17
- package/dist/hour.vo.js +22 -39
- package/dist/iban-mask.service.js +6 -3
- package/dist/iban.vo.d.ts +6 -4
- package/dist/iban.vo.js +7 -5
- package/dist/image.vo.d.ts +8 -2
- package/dist/image.vo.js +14 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/language.vo.d.ts +4 -1
- package/dist/language.vo.js +5 -3
- package/dist/mean.service.d.ts +4 -2
- package/dist/mean.service.js +9 -5
- package/dist/min-max-scaler.service.d.ts +22 -14
- package/dist/min-max-scaler.service.js +16 -15
- package/dist/minute.vo.d.ts +5 -6
- package/dist/minute.vo.js +14 -14
- package/dist/money.vo.d.ts +13 -2
- package/dist/money.vo.js +18 -13
- package/dist/outlier-detector.service.d.ts +2 -1
- package/dist/outlier-detector.service.js +5 -3
- package/dist/percentage.service.d.ts +3 -2
- package/dist/percentage.service.js +3 -2
- package/dist/population-standard-deviation.service.d.ts +3 -2
- package/dist/population-standard-deviation.service.js +5 -4
- package/dist/random.service.d.ts +6 -0
- package/dist/random.service.js +12 -6
- package/dist/rounding.adapter.d.ts +16 -0
- package/dist/{rounding.service.js → rounding.adapter.js} +8 -7
- package/dist/rounding.port.d.ts +3 -0
- package/dist/rounding.port.js +1 -0
- package/dist/simple-linear-regression.service.d.ts +11 -4
- package/dist/simple-linear-regression.service.js +39 -30
- package/dist/size.vo.js +1 -1
- package/dist/stopwatch.service.d.ts +1 -1
- package/dist/stopwatch.service.js +3 -4
- package/dist/sum.service.d.ts +2 -1
- package/dist/sum.service.js +11 -0
- package/dist/time.service.js +1 -1
- package/dist/timestamp.vo.d.ts +3 -0
- package/dist/timestamp.vo.js +7 -1
- package/dist/timezone.vo.d.ts +3 -0
- package/dist/timezone.vo.js +4 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/visually-unambiguous-characters-generator.service.js +0 -1
- package/dist/weight.vo.d.ts +4 -4
- package/dist/weight.vo.js +1 -1
- package/dist/z-score.service.d.ts +3 -2
- package/dist/z-score.service.js +3 -2
- package/package.json +2 -2
- package/readme.md +4 -2
- package/src/age.vo.ts +24 -14
- package/src/api-key.vo.ts +9 -1
- package/src/clock-format.service.ts +15 -0
- package/src/clock.vo.ts +24 -43
- package/src/height.vo.ts +12 -11
- package/src/hour-format.service.ts +21 -0
- package/src/hour.vo.ts +24 -47
- package/src/iban-mask.service.ts +8 -3
- package/src/iban.vo.ts +10 -8
- package/src/image.vo.ts +19 -4
- package/src/index.ts +2 -2
- package/src/language.vo.ts +7 -3
- package/src/mean.service.ts +13 -5
- package/src/min-max-scaler.service.ts +39 -24
- package/src/minute.vo.ts +18 -15
- package/src/money.vo.ts +26 -23
- package/src/outlier-detector.service.ts +6 -4
- package/src/percentage.service.ts +6 -7
- package/src/population-standard-deviation.service.ts +8 -5
- package/src/random.service.ts +16 -8
- package/src/relative-date.vo.ts +0 -1
- package/src/rounding.adapter.ts +33 -0
- package/src/rounding.port.ts +3 -0
- package/src/simple-linear-regression.service.ts +41 -31
- package/src/size.vo.ts +1 -1
- package/src/stopwatch.service.ts +4 -6
- package/src/sum.service.ts +15 -1
- package/src/time.service.ts +1 -1
- package/src/timestamp.vo.ts +9 -1
- package/src/timezone.vo.ts +15 -15
- package/src/visually-unambiguous-characters-generator.service.ts +0 -1
- package/src/weight.vo.ts +5 -4
- package/src/z-score.service.ts +6 -3
- package/dist/dates-of-the-week.vo.d.ts +0 -9
- package/dist/dates-of-the-week.vo.js +0 -10
- package/dist/rounding.service.d.ts +0 -17
- package/src/dates-of-the-week.vo.ts +0 -9
- package/src/rounding.service.ts +0 -31
package/dist/age.vo.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
2
|
import type { TimestampType } from "./timestamp.vo";
|
|
3
3
|
export declare const AgeValueError: {
|
|
4
|
-
error:
|
|
4
|
+
readonly error: "invalid.age";
|
|
5
5
|
};
|
|
6
|
+
export declare const InvalidBirthdateInFutureError: "invalid.birthdate_in_future";
|
|
7
|
+
export declare const InvalidBirthdateError: "invalid.birthdate";
|
|
6
8
|
export declare class Age {
|
|
7
9
|
private readonly value;
|
|
8
10
|
static readonly MIN = 1;
|
|
@@ -11,12 +13,12 @@ export declare class Age {
|
|
|
11
13
|
private constructor();
|
|
12
14
|
get(): number;
|
|
13
15
|
compare(other: Age): -1 | 0 | 1;
|
|
14
|
-
equals(
|
|
15
|
-
isOlderThan(
|
|
16
|
-
isYoungerThan(
|
|
17
|
-
isAdult(
|
|
16
|
+
equals(other: Age): boolean;
|
|
17
|
+
isOlderThan(other: Age): boolean;
|
|
18
|
+
isYoungerThan(other: Age): boolean;
|
|
19
|
+
isAdult(minimumAge: Age): boolean;
|
|
18
20
|
static fromValue(candidate: number): Age;
|
|
19
|
-
static
|
|
21
|
+
static fromBirthdateEpochMs(params: {
|
|
20
22
|
birthdate: TimestampType;
|
|
21
23
|
now: TimestampType;
|
|
22
24
|
}): Age;
|
|
@@ -24,4 +26,6 @@ export declare class Age {
|
|
|
24
26
|
birthdate: string;
|
|
25
27
|
now: TimestampType;
|
|
26
28
|
}): Age;
|
|
29
|
+
toJSON(): number;
|
|
30
|
+
toString(): string;
|
|
27
31
|
}
|
package/dist/age.vo.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { differenceInYears } from "date-fns";
|
|
2
2
|
import { z } from "zod/v4";
|
|
3
3
|
export const AgeValueError = { error: "invalid.age" };
|
|
4
|
+
export const InvalidBirthdateInFutureError = "invalid.birthdate_in_future";
|
|
5
|
+
export const InvalidBirthdateError = "invalid.birthdate";
|
|
4
6
|
export class Age {
|
|
5
7
|
value;
|
|
6
8
|
static MIN = 1;
|
|
@@ -20,30 +22,36 @@ export class Age {
|
|
|
20
22
|
compare(other) {
|
|
21
23
|
return this.value === other.value ? 0 : this.value < other.value ? -1 : 1;
|
|
22
24
|
}
|
|
23
|
-
equals(
|
|
24
|
-
return this.
|
|
25
|
+
equals(other) {
|
|
26
|
+
return this.value === other.value;
|
|
25
27
|
}
|
|
26
|
-
isOlderThan(
|
|
27
|
-
return this.
|
|
28
|
+
isOlderThan(other) {
|
|
29
|
+
return this.value > other.value;
|
|
28
30
|
}
|
|
29
|
-
isYoungerThan(
|
|
30
|
-
return this.
|
|
31
|
+
isYoungerThan(other) {
|
|
32
|
+
return this.value < other.value;
|
|
31
33
|
}
|
|
32
|
-
isAdult(
|
|
33
|
-
return this.
|
|
34
|
+
isAdult(minimumAge) {
|
|
35
|
+
return this.value >= minimumAge.value;
|
|
34
36
|
}
|
|
35
37
|
static fromValue(candidate) {
|
|
36
38
|
return new Age(Age.AgeValue.parse(candidate));
|
|
37
39
|
}
|
|
38
|
-
static
|
|
40
|
+
static fromBirthdateEpochMs(params) {
|
|
39
41
|
if (params.birthdate > params.now)
|
|
40
|
-
throw new Error(
|
|
42
|
+
throw new Error(InvalidBirthdateInFutureError);
|
|
41
43
|
return Age.fromValue(differenceInYears(params.now, params.birthdate));
|
|
42
44
|
}
|
|
43
45
|
static fromBirthdate(params) {
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
46
|
-
throw new Error(
|
|
47
|
-
return Age.fromValue(differenceInYears(params.now,
|
|
46
|
+
const birthdateMs = new Date(params.birthdate).getTime();
|
|
47
|
+
if (birthdateMs > params.now)
|
|
48
|
+
throw new Error(InvalidBirthdateInFutureError);
|
|
49
|
+
return Age.fromValue(differenceInYears(params.now, birthdateMs));
|
|
50
|
+
}
|
|
51
|
+
toJSON() {
|
|
52
|
+
return this.get();
|
|
53
|
+
}
|
|
54
|
+
toString() {
|
|
55
|
+
return String(this.value);
|
|
48
56
|
}
|
|
49
57
|
}
|
package/dist/api-key.vo.d.ts
CHANGED
package/dist/api-key.vo.js
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export const
|
|
2
|
+
export const ApiKeyError = { error: "invalid.api.key" };
|
|
3
|
+
export const ApiKey = z
|
|
4
|
+
.string(ApiKeyError)
|
|
5
|
+
.trim()
|
|
6
|
+
.length(64, ApiKeyError)
|
|
7
|
+
.regex(/^[0-9a-f]{64}$/i, ApiKeyError)
|
|
8
|
+
.brand("ApiKey");
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Hour } from "./hour.vo";
|
|
2
|
+
import type { Minute } from "./minute.vo";
|
|
3
|
+
export type ClockFormatter = (hour: Hour, minute: Minute) => string;
|
|
4
|
+
declare enum ClockFormatterEnum {
|
|
5
|
+
TWENTY_FOUR_HOURS = "TWENTY_FOUR_HOURS",
|
|
6
|
+
TWELVE_HOURS = "TWELVE_HOURS"
|
|
7
|
+
}
|
|
8
|
+
export declare const ClockFormatters: Record<ClockFormatterEnum, ClockFormatter>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HourFormatters } from "./hour-format.service";
|
|
2
|
+
var ClockFormatterEnum;
|
|
3
|
+
(function (ClockFormatterEnum) {
|
|
4
|
+
ClockFormatterEnum["TWENTY_FOUR_HOURS"] = "TWENTY_FOUR_HOURS";
|
|
5
|
+
ClockFormatterEnum["TWELVE_HOURS"] = "TWELVE_HOURS";
|
|
6
|
+
})(ClockFormatterEnum || (ClockFormatterEnum = {}));
|
|
7
|
+
export const ClockFormatters = {
|
|
8
|
+
TWENTY_FOUR_HOURS: (hour, minute) => `${hour.toString()}:${minute.toString()}`,
|
|
9
|
+
TWELVE_HOURS: (hour, minute) => `${hour.format(HourFormatters.TWELVE_HOURS)}:${minute.toString()}`,
|
|
10
|
+
};
|
package/dist/clock.vo.d.ts
CHANGED
|
@@ -1,27 +1,20 @@
|
|
|
1
|
+
import { type ClockFormatter } from "./clock-format.service";
|
|
1
2
|
import { Hour } from "./hour.vo";
|
|
2
3
|
import { Minute } from "./minute.vo";
|
|
3
4
|
import type { TimestampType } from "./timestamp.vo";
|
|
4
|
-
export type ClockFormatter = (hour: Hour, minute: Minute) => string;
|
|
5
|
-
declare enum ClockFormatterEnum {
|
|
6
|
-
TWENTY_FOUR_HOURS = "TWENTY_FOUR_HOURS",
|
|
7
|
-
TWELVE_HOURS = "TWELVE_HOURS"
|
|
8
|
-
}
|
|
9
|
-
export declare const ClockFormatters: Record<ClockFormatterEnum, ClockFormatter>;
|
|
10
5
|
export declare class Clock {
|
|
11
6
|
private readonly hour;
|
|
12
7
|
private readonly minute;
|
|
13
8
|
private readonly formatter;
|
|
14
9
|
constructor(hour: Hour, minute: Minute, formatter?: ClockFormatter);
|
|
15
|
-
static
|
|
16
|
-
get(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
minute: number;
|
|
20
|
-
};
|
|
21
|
-
formatted: string;
|
|
10
|
+
static fromEpochMs(timestamp: TimestampType, formatter?: ClockFormatter): Clock;
|
|
11
|
+
get(): {
|
|
12
|
+
hour: number;
|
|
13
|
+
minute: number;
|
|
22
14
|
};
|
|
15
|
+
format(formatter?: ClockFormatter): string;
|
|
16
|
+
toString(): string;
|
|
23
17
|
equals(another: Clock): boolean;
|
|
24
18
|
isAfter(another: Clock): boolean;
|
|
25
19
|
isBefore(another: Clock): boolean;
|
|
26
20
|
}
|
|
27
|
-
export {};
|
package/dist/clock.vo.js
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ClockFormatters } from "./clock-format.service";
|
|
2
|
+
import { Hour } from "./hour.vo";
|
|
2
3
|
import { Minute } from "./minute.vo";
|
|
3
|
-
var ClockFormatterEnum;
|
|
4
|
-
(function (ClockFormatterEnum) {
|
|
5
|
-
ClockFormatterEnum["TWENTY_FOUR_HOURS"] = "TWENTY_FOUR_HOURS";
|
|
6
|
-
ClockFormatterEnum["TWELVE_HOURS"] = "TWELVE_HOURS";
|
|
7
|
-
})(ClockFormatterEnum || (ClockFormatterEnum = {}));
|
|
8
|
-
export const ClockFormatters = {
|
|
9
|
-
TWENTY_FOUR_HOURS: (hour, minute) => `${hour.get().formatted}:${minute.get().formatted}`,
|
|
10
|
-
TWELVE_HOURS: (hour, minute) => `${hour.get(HourFormatters.TWELVE_HOURS).formatted}:${minute.get().formatted}`,
|
|
11
|
-
};
|
|
12
4
|
export class Clock {
|
|
13
5
|
hour;
|
|
14
6
|
minute;
|
|
@@ -18,37 +10,36 @@ export class Clock {
|
|
|
18
10
|
this.minute = minute;
|
|
19
11
|
this.formatter = formatter ?? ClockFormatters.TWENTY_FOUR_HOURS;
|
|
20
12
|
}
|
|
21
|
-
static
|
|
22
|
-
const hour = Hour.
|
|
23
|
-
const minute = Minute.
|
|
13
|
+
static fromEpochMs(timestamp, formatter) {
|
|
14
|
+
const hour = Hour.fromEpochMs(timestamp);
|
|
15
|
+
const minute = Minute.fromEpochMs(timestamp);
|
|
24
16
|
return new Clock(hour, minute, formatter);
|
|
25
17
|
}
|
|
26
|
-
get(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
get() {
|
|
19
|
+
return { hour: this.hour.get(), minute: this.minute.get() };
|
|
20
|
+
}
|
|
21
|
+
format(formatter) {
|
|
22
|
+
const chosen = formatter ?? this.formatter;
|
|
23
|
+
return chosen(this.hour, this.minute);
|
|
24
|
+
}
|
|
25
|
+
toString() {
|
|
26
|
+
return this.format();
|
|
32
27
|
}
|
|
33
28
|
equals(another) {
|
|
34
|
-
return
|
|
29
|
+
return this.hour.get() === another.hour.get() && this.minute.get() === another.minute.get();
|
|
35
30
|
}
|
|
36
31
|
isAfter(another) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
return false;
|
|
32
|
+
const thisHour = this.hour.get();
|
|
33
|
+
const otherHour = another.hour.get();
|
|
34
|
+
if (thisHour !== otherHour)
|
|
35
|
+
return thisHour > otherHour;
|
|
36
|
+
return this.minute.get() > another.minute.get();
|
|
44
37
|
}
|
|
45
38
|
isBefore(another) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
return false;
|
|
39
|
+
const thisHour = this.hour.get();
|
|
40
|
+
const otherHour = another.hour.get();
|
|
41
|
+
if (thisHour !== otherHour)
|
|
42
|
+
return thisHour < otherHour;
|
|
43
|
+
return this.minute.get() < another.minute.get();
|
|
53
44
|
}
|
|
54
45
|
}
|
package/dist/height.vo.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { RoundingPort } from "./rounding.port";
|
|
2
2
|
export declare enum HeightUnit {
|
|
3
3
|
cm = "cm",
|
|
4
4
|
ft_in = "ft_in"
|
|
@@ -9,17 +9,17 @@ export declare class Height {
|
|
|
9
9
|
private static readonly MILLIMETERS_PER_INCH;
|
|
10
10
|
private static readonly INCHES_PER_FOOT;
|
|
11
11
|
private constructor();
|
|
12
|
-
static fromCentimeters(centimeters: number, rounding?:
|
|
13
|
-
static fromFeetInches(feet: number, inches?: number, rounding?:
|
|
14
|
-
static fromMillimeters(millimeters: number, rounding?:
|
|
12
|
+
static fromCentimeters(centimeters: number, rounding?: RoundingPort): Height;
|
|
13
|
+
static fromFeetInches(feet: number, inches?: number, rounding?: RoundingPort): Height;
|
|
14
|
+
static fromMillimeters(millimeters: number, rounding?: RoundingPort): Height;
|
|
15
15
|
static zero(): Height;
|
|
16
16
|
toMillimeters(): number;
|
|
17
|
-
toCentimeters(rounding?:
|
|
18
|
-
toFeetInches(rounding?:
|
|
17
|
+
toCentimeters(rounding?: RoundingPort): number;
|
|
18
|
+
toFeetInches(rounding?: RoundingPort): {
|
|
19
19
|
feet: number;
|
|
20
20
|
inches: number;
|
|
21
21
|
};
|
|
22
|
-
format(unit: HeightUnit,
|
|
22
|
+
format(unit: HeightUnit, rounding?: RoundingPort): string;
|
|
23
23
|
equals(other: Height): boolean;
|
|
24
24
|
compare(other: Height): -1 | 0 | 1;
|
|
25
25
|
greaterThan(other: Height): boolean;
|
package/dist/height.vo.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
import { RoundToDecimal, RoundToNearest } from "./rounding.
|
|
2
|
+
import { RoundToDecimal, RoundToNearest } from "./rounding.adapter";
|
|
3
3
|
const FiniteNumericValue = z.number().refine(Number.isFinite, { message: "Expected a finite number" });
|
|
4
4
|
const NonNegativeNumericValue = FiniteNumericValue.min(0, { message: "Must be greater than or equal to 0" });
|
|
5
5
|
const NonNegativeIntegerMillimeters = FiniteNumericValue.int().min(0, {
|
|
@@ -61,15 +61,15 @@ export class Height {
|
|
|
61
61
|
const inches = integerInches % Height.INCHES_PER_FOOT;
|
|
62
62
|
return { feet, inches };
|
|
63
63
|
}
|
|
64
|
-
format(unit,
|
|
64
|
+
format(unit, rounding) {
|
|
65
65
|
return {
|
|
66
66
|
[HeightUnit.cm]: () => {
|
|
67
|
-
const
|
|
68
|
-
return `${this.toCentimeters(
|
|
67
|
+
const chosen = rounding ?? new RoundToDecimal(1);
|
|
68
|
+
return `${this.toCentimeters(chosen)} cm`;
|
|
69
69
|
},
|
|
70
70
|
[HeightUnit.ft_in]: () => {
|
|
71
|
-
const
|
|
72
|
-
const { feet, inches } = this.toFeetInches(
|
|
71
|
+
const chosen = rounding ?? new RoundToNearest();
|
|
72
|
+
const { feet, inches } = this.toFeetInches(chosen);
|
|
73
73
|
return `${feet}′${inches}″`;
|
|
74
74
|
},
|
|
75
75
|
}[unit]();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type HourFormatter = (value: number) => string;
|
|
2
|
+
declare enum HourFormatterEnum {
|
|
3
|
+
TWENTY_FOUR_HOURS = "TWENTY_FOUR_HOURS",
|
|
4
|
+
TWENTY_FOUR_HOURS_WO_PADDING = "TWENTY_FOUR_HOURS_WO_PADDING",
|
|
5
|
+
AM_PM = "AM_PM",
|
|
6
|
+
TWELVE_HOURS = "TWELVE_HOURS",
|
|
7
|
+
TWELVE_HOURS_WO_PADDING = "TWELVE_HOURS_WO_PADDING"
|
|
8
|
+
}
|
|
9
|
+
export declare const HourFormatters: Record<HourFormatterEnum, HourFormatter>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var HourFormatterEnum;
|
|
2
|
+
(function (HourFormatterEnum) {
|
|
3
|
+
HourFormatterEnum["TWENTY_FOUR_HOURS"] = "TWENTY_FOUR_HOURS";
|
|
4
|
+
HourFormatterEnum["TWENTY_FOUR_HOURS_WO_PADDING"] = "TWENTY_FOUR_HOURS_WO_PADDING";
|
|
5
|
+
HourFormatterEnum["AM_PM"] = "AM_PM";
|
|
6
|
+
HourFormatterEnum["TWELVE_HOURS"] = "TWELVE_HOURS";
|
|
7
|
+
HourFormatterEnum["TWELVE_HOURS_WO_PADDING"] = "TWELVE_HOURS_WO_PADDING";
|
|
8
|
+
})(HourFormatterEnum || (HourFormatterEnum = {}));
|
|
9
|
+
export const HourFormatters = {
|
|
10
|
+
TWENTY_FOUR_HOURS: (value) => value.toString().padStart(2, "0"),
|
|
11
|
+
TWENTY_FOUR_HOURS_WO_PADDING: (value) => value.toString(),
|
|
12
|
+
AM_PM: (value) => {
|
|
13
|
+
const twelveHourValue = value % 12 || 12;
|
|
14
|
+
const suffix = value < 12 ? "a.m." : "p.m.";
|
|
15
|
+
return `${twelveHourValue} ${suffix}`;
|
|
16
|
+
},
|
|
17
|
+
TWELVE_HOURS: (value) => (value % 12 || 12).toString().padStart(2, "0"),
|
|
18
|
+
TWELVE_HOURS_WO_PADDING: (value) => (value % 12 || 12).toString(),
|
|
19
|
+
};
|
package/dist/hour.vo.d.ts
CHANGED
|
@@ -1,26 +1,17 @@
|
|
|
1
|
+
import { type HourFormatter } from "./hour-format.service";
|
|
1
2
|
import type { TimestampType } from "./timestamp.vo";
|
|
2
|
-
export
|
|
3
|
-
export declare enum HourFormatterEnum {
|
|
4
|
-
TWENTY_FOUR_HOURS = "TWENTY_FOUR_HOURS",
|
|
5
|
-
TWENTY_FOUR_HOURS_WO_PADDING = "TWENTY_FOUR_HOURS_WO_PADDING",
|
|
6
|
-
AM_PM = "AM_PM",
|
|
7
|
-
TWELVE_HOURS = "TWELVE_HOURS",
|
|
8
|
-
TWELVE_HOURS_WO_PADDING = "TWELVE_HOURS_WO_PADDING"
|
|
9
|
-
}
|
|
10
|
-
export declare const HourFormatters: Record<HourFormatterEnum, HourFormatter>;
|
|
3
|
+
export declare const HourValueError: "invalid.hour";
|
|
11
4
|
export declare class Hour {
|
|
12
5
|
private readonly value;
|
|
13
|
-
private readonly formatter;
|
|
14
6
|
static readonly ZERO: Hour;
|
|
15
7
|
static readonly MAX: Hour;
|
|
16
|
-
constructor(candidate: number
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
constructor(candidate: number);
|
|
9
|
+
static fromEpochMs(timestamp: TimestampType): Hour;
|
|
10
|
+
get(): number;
|
|
11
|
+
toString(): string;
|
|
12
|
+
format(formatter: HourFormatter): string;
|
|
21
13
|
equals(another: Hour): boolean;
|
|
22
14
|
isAfter(another: Hour): boolean;
|
|
23
15
|
isBefore(another: Hour): boolean;
|
|
24
|
-
static
|
|
25
|
-
static list(formatter?: HourFormatter): Hour[];
|
|
16
|
+
static list(): readonly Hour[];
|
|
26
17
|
}
|
package/dist/hour.vo.js
CHANGED
|
@@ -1,54 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
HourFormatterEnum["TWENTY_FOUR_HOURS"] = "TWENTY_FOUR_HOURS";
|
|
4
|
-
HourFormatterEnum["TWENTY_FOUR_HOURS_WO_PADDING"] = "TWENTY_FOUR_HOURS_WO_PADDING";
|
|
5
|
-
HourFormatterEnum["AM_PM"] = "AM_PM";
|
|
6
|
-
HourFormatterEnum["TWELVE_HOURS"] = "TWELVE_HOURS";
|
|
7
|
-
HourFormatterEnum["TWELVE_HOURS_WO_PADDING"] = "TWELVE_HOURS_WO_PADDING";
|
|
8
|
-
})(HourFormatterEnum || (HourFormatterEnum = {}));
|
|
9
|
-
export const HourFormatters = {
|
|
10
|
-
TWENTY_FOUR_HOURS: (value) => value.toString().padStart(2, "0"),
|
|
11
|
-
TWENTY_FOUR_HOURS_WO_PADDING: (value) => value.toString(),
|
|
12
|
-
AM_PM: (value) => {
|
|
13
|
-
const twelveHour = value % 12 || 12;
|
|
14
|
-
return `${twelveHour.toString()} ${value < 12 ? "a.m." : "p.m."}`;
|
|
15
|
-
},
|
|
16
|
-
TWELVE_HOURS: (value) => (value % 12 || 12).toString().padStart(2, "0"),
|
|
17
|
-
TWELVE_HOURS_WO_PADDING: (value) => (value % 12 || 12).toString(),
|
|
18
|
-
};
|
|
1
|
+
import { HourFormatters } from "./hour-format.service";
|
|
2
|
+
export const HourValueError = "invalid.hour";
|
|
19
3
|
export class Hour {
|
|
20
4
|
value;
|
|
21
|
-
formatter;
|
|
22
5
|
static ZERO = new Hour(0);
|
|
23
6
|
static MAX = new Hour(23);
|
|
24
|
-
constructor(candidate
|
|
25
|
-
if (!Number.isInteger(candidate))
|
|
26
|
-
throw new Error(
|
|
27
|
-
|
|
28
|
-
throw new Error("Invalid hour");
|
|
29
|
-
if (candidate >= 24)
|
|
30
|
-
throw new Error("Invalid hour");
|
|
7
|
+
constructor(candidate) {
|
|
8
|
+
if (!Number.isInteger(candidate) || candidate < 0 || candidate >= 24) {
|
|
9
|
+
throw new Error(HourValueError);
|
|
10
|
+
}
|
|
31
11
|
this.value = candidate;
|
|
32
|
-
this.formatter = formatter ?? HourFormatters.TWENTY_FOUR_HOURS;
|
|
33
12
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
13
|
+
static fromEpochMs(timestamp) {
|
|
14
|
+
return new Hour(new Date(timestamp).getUTCHours());
|
|
15
|
+
}
|
|
16
|
+
get() {
|
|
17
|
+
return this.value;
|
|
18
|
+
}
|
|
19
|
+
toString() {
|
|
20
|
+
return HourFormatters.TWENTY_FOUR_HOURS(this.value);
|
|
21
|
+
}
|
|
22
|
+
format(formatter) {
|
|
23
|
+
return formatter(this.value);
|
|
37
24
|
}
|
|
38
25
|
equals(another) {
|
|
39
|
-
return this.value === another.
|
|
26
|
+
return this.value === another.value;
|
|
40
27
|
}
|
|
41
28
|
isAfter(another) {
|
|
42
|
-
return this.value > another.
|
|
29
|
+
return this.value > another.value;
|
|
43
30
|
}
|
|
44
31
|
isBefore(another) {
|
|
45
|
-
return this.value < another.
|
|
46
|
-
}
|
|
47
|
-
static fromUtcTimestamp(timestamp, formatter) {
|
|
48
|
-
const hours = new Date(timestamp).getUTCHours();
|
|
49
|
-
return new Hour(hours, formatter);
|
|
32
|
+
return this.value < another.value;
|
|
50
33
|
}
|
|
51
|
-
static list(
|
|
52
|
-
return Array.from({ length: 24 }
|
|
34
|
+
static list() {
|
|
35
|
+
return Array.from({ length: 24 }, (_, index) => new Hour(index));
|
|
53
36
|
}
|
|
54
37
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export class IbanMask {
|
|
2
2
|
static censor(iban) {
|
|
3
3
|
const value = iban.format();
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const FIRST_SPACE_INDEX = 4;
|
|
5
|
+
const LAST_SPACE_START_INDEX = value.length - 5;
|
|
6
|
+
const start = value.slice(0, FIRST_SPACE_INDEX);
|
|
7
|
+
const middle = value.slice(FIRST_SPACE_INDEX + 1, LAST_SPACE_START_INDEX);
|
|
6
8
|
const end = value.slice(-4);
|
|
7
|
-
|
|
9
|
+
const maskedMiddle = middle.replace(/[A-Z0-9]/g, "*");
|
|
10
|
+
return `${start} ${maskedMiddle} ${end}`;
|
|
8
11
|
}
|
|
9
12
|
}
|
package/dist/iban.vo.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
declare const
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export declare const IBANError: {
|
|
3
|
+
readonly error: "invalid.iban.format";
|
|
4
|
+
};
|
|
5
|
+
export declare const IBANValue: z.core.$ZodBranded<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, "IBAN">;
|
|
6
|
+
export type IBANValueType = z.infer<typeof IBANValue>;
|
|
7
|
+
export type IBANCountryCode = string;
|
|
5
8
|
export declare class IBAN {
|
|
6
9
|
private readonly value;
|
|
7
10
|
constructor(value: string);
|
|
@@ -10,4 +13,3 @@ export declare class IBAN {
|
|
|
10
13
|
get countryCode(): IBANCountryCode;
|
|
11
14
|
equals(other: IBAN): boolean;
|
|
12
15
|
}
|
|
13
|
-
export {};
|
package/dist/iban.vo.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
|
|
2
|
+
export const IBANError = { error: "invalid.iban.format" };
|
|
3
|
+
// 2-letter country code + 2 digits + 11–30 alphanumerics (overall 15–34 chars)
|
|
3
4
|
const IBAN_REGEX = /^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$/;
|
|
4
|
-
const
|
|
5
|
-
.string()
|
|
5
|
+
export const IBANValue = z
|
|
6
|
+
.string(IBANError)
|
|
6
7
|
.trim()
|
|
7
8
|
.toUpperCase()
|
|
8
9
|
.transform((val) => val.replace(/\s+/g, ""))
|
|
9
|
-
.refine((iban) => IBAN_REGEX.test(iban),
|
|
10
|
+
.refine((iban) => IBAN_REGEX.test(iban), IBANError)
|
|
11
|
+
.brand("IBAN");
|
|
10
12
|
export class IBAN {
|
|
11
13
|
value;
|
|
12
14
|
constructor(value) {
|
|
13
|
-
this.value =
|
|
15
|
+
this.value = IBANValue.parse(value);
|
|
14
16
|
}
|
|
15
17
|
toString() {
|
|
16
18
|
return this.value;
|
package/dist/image.vo.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
+
export declare const ImageWidthError: {
|
|
3
|
+
readonly error: "invalid.image.width";
|
|
4
|
+
};
|
|
5
|
+
export declare const ImageHeightError: {
|
|
6
|
+
readonly error: "invalid.image.height";
|
|
7
|
+
};
|
|
2
8
|
export declare const ImageWidth: z.core.$ZodBranded<z.ZodNumber, "image-width">;
|
|
3
|
-
export type
|
|
9
|
+
export type ImageWidthType = z.infer<typeof ImageWidth>;
|
|
4
10
|
export declare const ImageHeight: z.core.$ZodBranded<z.ZodNumber, "image-height">;
|
|
5
|
-
export type
|
|
11
|
+
export type ImageHeightType = z.infer<typeof ImageHeight>;
|
package/dist/image.vo.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export const
|
|
3
|
-
export const
|
|
2
|
+
export const ImageWidthError = { error: "invalid.image.width" };
|
|
3
|
+
export const ImageHeightError = { error: "invalid.image.height" };
|
|
4
|
+
export const ImageWidth = z
|
|
5
|
+
.number(ImageWidthError)
|
|
6
|
+
.int(ImageWidthError)
|
|
7
|
+
.positive(ImageWidthError)
|
|
8
|
+
.max(10_000, ImageWidthError)
|
|
9
|
+
.brand("image-width");
|
|
10
|
+
export const ImageHeight = z
|
|
11
|
+
.number(ImageHeightError)
|
|
12
|
+
.int(ImageHeightError)
|
|
13
|
+
.positive(ImageHeightError)
|
|
14
|
+
.max(10_000, ImageHeightError)
|
|
15
|
+
.brand("image-height");
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ export * from "./clock.vo";
|
|
|
5
5
|
export * from "./date-calculator.service";
|
|
6
6
|
export * from "./date-formatter.service";
|
|
7
7
|
export * from "./date-range.vo";
|
|
8
|
-
export * from "./dates-of-the-week.vo";
|
|
9
8
|
export * from "./day.vo";
|
|
10
9
|
export * from "./day-iso-id.vo";
|
|
11
10
|
export * from "./directory-path-absolute.vo";
|
|
@@ -50,7 +49,8 @@ export * from "./rate-limiter.service";
|
|
|
50
49
|
export * from "./relative-date.vo";
|
|
51
50
|
export * from "./reordering.service";
|
|
52
51
|
export * from "./revision.vo";
|
|
53
|
-
export * from "./rounding.
|
|
52
|
+
export * from "./rounding.adapter";
|
|
53
|
+
export * from "./rounding.port";
|
|
54
54
|
export * from "./simple-linear-regression.service";
|
|
55
55
|
export * from "./size.vo";
|
|
56
56
|
export * from "./stepper.service";
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,6 @@ export * from "./clock.vo";
|
|
|
5
5
|
export * from "./date-calculator.service";
|
|
6
6
|
export * from "./date-formatter.service";
|
|
7
7
|
export * from "./date-range.vo";
|
|
8
|
-
export * from "./dates-of-the-week.vo";
|
|
9
8
|
export * from "./day.vo";
|
|
10
9
|
export * from "./day-iso-id.vo";
|
|
11
10
|
export * from "./directory-path-absolute.vo";
|
|
@@ -50,7 +49,8 @@ export * from "./rate-limiter.service";
|
|
|
50
49
|
export * from "./relative-date.vo";
|
|
51
50
|
export * from "./reordering.service";
|
|
52
51
|
export * from "./revision.vo";
|
|
53
|
-
export * from "./rounding.
|
|
52
|
+
export * from "./rounding.adapter";
|
|
53
|
+
export * from "./rounding.port";
|
|
54
54
|
export * from "./simple-linear-regression.service";
|
|
55
55
|
export * from "./size.vo";
|
|
56
56
|
export * from "./stepper.service";
|
package/dist/language.vo.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const LanguageError: {
|
|
3
|
+
readonly error: "invalid.language";
|
|
4
|
+
};
|
|
5
|
+
export declare const Language: z.core.$ZodBranded<z.ZodString, "Language">;
|
|
3
6
|
export type LanguageType = z.infer<typeof Language>;
|
package/dist/language.vo.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
+
export const LanguageError = { error: "invalid.language" };
|
|
2
3
|
export const Language = z
|
|
3
|
-
.string()
|
|
4
|
-
.length(2)
|
|
5
|
-
.regex(/^[a-z]{2}$/,
|
|
4
|
+
.string(LanguageError)
|
|
5
|
+
.length(2, LanguageError)
|
|
6
|
+
.regex(/^[a-z]{2}$/, LanguageError)
|
|
7
|
+
.brand("Language");
|
package/dist/mean.service.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { RoundingPort } from "./rounding.port";
|
|
2
|
+
export declare const MeanEmptyValuesError: "mean.values.empty";
|
|
2
3
|
export declare class Mean {
|
|
3
|
-
static
|
|
4
|
+
private static readonly DEFAULT_ROUNDING;
|
|
5
|
+
static calculate(values: number[], rounding?: RoundingPort): number;
|
|
4
6
|
}
|
package/dist/mean.service.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { RoundToDecimal } from "./rounding.
|
|
1
|
+
import { RoundToDecimal } from "./rounding.adapter";
|
|
2
2
|
import { Sum } from "./sum.service";
|
|
3
|
+
export const MeanEmptyValuesError = "mean.values.empty";
|
|
3
4
|
export class Mean {
|
|
4
|
-
static
|
|
5
|
+
static DEFAULT_ROUNDING = new RoundToDecimal(2);
|
|
6
|
+
static calculate(values, rounding) {
|
|
5
7
|
if (values.length === 0)
|
|
6
|
-
throw new Error(
|
|
7
|
-
const
|
|
8
|
-
|
|
8
|
+
throw new Error(MeanEmptyValuesError);
|
|
9
|
+
const sum = Sum.of(values);
|
|
10
|
+
const mean = sum / values.length;
|
|
11
|
+
const chosen = rounding ?? Mean.DEFAULT_ROUNDING;
|
|
12
|
+
return chosen.round(mean);
|
|
9
13
|
}
|
|
10
14
|
}
|