@bgord/tools 1.3.14 → 1.3.16
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-years.vo.js +2 -2
- package/dist/age.vo.d.ts +1 -1
- package/dist/age.vo.js +1 -1
- package/dist/date-range.vo.d.ts +3 -1
- package/dist/date-range.vo.js +4 -1
- package/dist/day.vo.d.ts +1 -1
- package/dist/day.vo.js +3 -3
- package/dist/distance.vo.d.ts +1 -2
- package/dist/distance.vo.js +3 -6
- package/dist/duration.service.js +1 -2
- package/dist/height.vo.d.ts +1 -2
- package/dist/height.vo.js +3 -12
- package/dist/hour-value.vo.d.ts +7 -0
- package/dist/hour-value.vo.js +10 -0
- package/dist/hour.vo.d.ts +3 -5
- package/dist/hour.vo.js +4 -8
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -3
- package/dist/mime-value.vo.d.ts +1 -4
- package/dist/mime-value.vo.js +0 -1
- package/dist/mime.vo.d.ts +0 -3
- package/dist/mime.vo.js +2 -2
- package/dist/minute-value.vo.d.ts +7 -0
- package/dist/minute-value.vo.js +10 -0
- package/dist/minute.vo.d.ts +3 -3
- package/dist/minute.vo.js +3 -3
- package/dist/money.vo.d.ts +4 -6
- package/dist/money.vo.js +12 -20
- package/dist/month.vo.js +5 -5
- package/dist/package-version-schema.vo.d.ts +2 -5
- package/dist/package-version-schema.vo.js +1 -5
- package/dist/package-version.vo.d.ts +1 -1
- package/dist/package-version.vo.js +5 -4
- package/dist/quarter.vo.js +2 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/week.vo.js +5 -3
- package/dist/weekday-iso-id.vo.js +2 -2
- package/dist/weekday.vo.d.ts +8 -22
- package/dist/weekday.vo.js +29 -66
- package/dist/year.vo.js +5 -5
- package/package.json +2 -2
- package/readme.md +2 -3
- package/dist/hour-format.service.d.ts +0 -10
- package/dist/hour-format.service.js +0 -19
- package/dist/hour-schema.vo.d.ts +0 -7
- package/dist/hour-schema.vo.js +0 -10
- package/dist/minute-schema.vo.d.ts +0 -7
- package/dist/minute-schema.vo.js +0 -10
package/dist/age-years.vo.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as z from "zod/v4";
|
|
2
2
|
export const AgeYearsError = { Type: "age.years.type", Invalid: "age.years.invalid" };
|
|
3
|
-
export const AgeYearsConstraints = { min:
|
|
3
|
+
export const AgeYearsConstraints = { min: 0, max: 130 };
|
|
4
4
|
// Stryker disable all
|
|
5
5
|
export const AgeYears = z
|
|
6
6
|
// Stryker restore all
|
|
7
7
|
.number(AgeYearsError.Type)
|
|
8
8
|
.int(AgeYearsError.Type)
|
|
9
|
-
.min(
|
|
9
|
+
.min(0, AgeYearsError.Invalid)
|
|
10
10
|
.max(130, AgeYearsError.Invalid)
|
|
11
11
|
.brand("AgeYears");
|
package/dist/age.vo.d.ts
CHANGED
package/dist/age.vo.js
CHANGED
|
@@ -21,7 +21,7 @@ export class Age {
|
|
|
21
21
|
return Age.fromValue(differenceInYears(params.now.ms, params.birthdate.ms));
|
|
22
22
|
}
|
|
23
23
|
static fromBirthdate(candidate) {
|
|
24
|
-
const birthdate = Timestamp.
|
|
24
|
+
const birthdate = Timestamp.fromDateLike(candidate.birthdate);
|
|
25
25
|
if (birthdate.isAfter(candidate.now))
|
|
26
26
|
throw new Error(AgeError.FutureBirthdate);
|
|
27
27
|
return Age.fromValue(differenceInYears(candidate.now.ms, birthdate.ms));
|
package/dist/date-range.vo.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Duration } from "./duration.service";
|
|
1
2
|
import type { Timestamp } from "./timestamp.vo";
|
|
2
3
|
export declare const DateRangeError: {
|
|
3
4
|
Invalid: string;
|
|
@@ -8,7 +9,8 @@ export declare class DateRange {
|
|
|
8
9
|
constructor(start: Timestamp, end: Timestamp);
|
|
9
10
|
getStart(): Timestamp;
|
|
10
11
|
getEnd(): Timestamp;
|
|
11
|
-
|
|
12
|
+
get(): [Timestamp, Timestamp];
|
|
13
|
+
getDuration(): Duration;
|
|
12
14
|
contains(timestamp: Timestamp): boolean;
|
|
13
15
|
equals(other: DateRange): boolean;
|
|
14
16
|
toString(): string;
|
package/dist/date-range.vo.js
CHANGED
|
@@ -14,9 +14,12 @@ export class DateRange {
|
|
|
14
14
|
getEnd() {
|
|
15
15
|
return this.end;
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
get() {
|
|
18
18
|
return [this.start, this.end];
|
|
19
19
|
}
|
|
20
|
+
getDuration() {
|
|
21
|
+
return this.end.difference(this.start);
|
|
22
|
+
}
|
|
20
23
|
contains(timestamp) {
|
|
21
24
|
return timestamp.isAfterOrEqual(this.start) && timestamp.isBeforeOrEqual(this.end);
|
|
22
25
|
}
|
package/dist/day.vo.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export declare class Day extends DateRange {
|
|
|
9
9
|
static fromNow(now: Timestamp): Day;
|
|
10
10
|
static fromIsoId(isoId: DayIsoIdType): Day;
|
|
11
11
|
toIsoId(): DayIsoIdType;
|
|
12
|
-
previous(): Day;
|
|
13
12
|
next(): Day;
|
|
13
|
+
previous(): Day;
|
|
14
14
|
shift(count: IntegerType): Day;
|
|
15
15
|
toString(): string;
|
|
16
16
|
}
|
package/dist/day.vo.js
CHANGED
|
@@ -27,12 +27,12 @@ export class Day extends DateRange {
|
|
|
27
27
|
const midday = this.getStart().add(Duration.Hours(12));
|
|
28
28
|
return DayIsoId.parse(formatISO(midday.ms, { representation: "date" }));
|
|
29
29
|
}
|
|
30
|
-
previous() {
|
|
31
|
-
return this.shift(Integer.parse(-1));
|
|
32
|
-
}
|
|
33
30
|
next() {
|
|
34
31
|
return this.shift(Integer.parse(1));
|
|
35
32
|
}
|
|
33
|
+
previous() {
|
|
34
|
+
return this.shift(Integer.parse(-1));
|
|
35
|
+
}
|
|
36
36
|
shift(count) {
|
|
37
37
|
return Day.fromTimestamp(this.getStart().add(Duration.Days(count)));
|
|
38
38
|
}
|
package/dist/distance.vo.d.ts
CHANGED
|
@@ -13,12 +13,11 @@ export declare class Distance {
|
|
|
13
13
|
static fromMiles(candidate: number, rounding?: RoundingStrategy): Distance;
|
|
14
14
|
get(): DistanceValueType;
|
|
15
15
|
add(distance: Distance): Distance;
|
|
16
|
-
subtract(
|
|
16
|
+
subtract(distance: Distance): Distance;
|
|
17
17
|
equals(another: Distance): boolean;
|
|
18
18
|
isLongerThan(another: Distance): boolean;
|
|
19
19
|
isShorterThan(another: Distance): boolean;
|
|
20
20
|
isZero(): boolean;
|
|
21
|
-
format(): string;
|
|
22
21
|
toString(): string;
|
|
23
22
|
toJSON(): number;
|
|
24
23
|
}
|
package/dist/distance.vo.js
CHANGED
|
@@ -25,8 +25,8 @@ export class Distance {
|
|
|
25
25
|
add(distance) {
|
|
26
26
|
return new Distance(DistanceValue.parse(this.value + distance.get()));
|
|
27
27
|
}
|
|
28
|
-
subtract(
|
|
29
|
-
const result = this.value -
|
|
28
|
+
subtract(distance) {
|
|
29
|
+
const result = this.value - distance.get();
|
|
30
30
|
if (result < Distance.ZERO)
|
|
31
31
|
throw new Error(DistanceError.SubtractResultLessThanZero);
|
|
32
32
|
return new Distance(DistanceValue.parse(result));
|
|
@@ -43,11 +43,8 @@ export class Distance {
|
|
|
43
43
|
isZero() {
|
|
44
44
|
return this.value === Distance.ZERO;
|
|
45
45
|
}
|
|
46
|
-
format() {
|
|
47
|
-
return this.value.toString();
|
|
48
|
-
}
|
|
49
46
|
toString() {
|
|
50
|
-
return this.
|
|
47
|
+
return this.value.toString();
|
|
51
48
|
}
|
|
52
49
|
toJSON() {
|
|
53
50
|
return this.value;
|
package/dist/duration.service.js
CHANGED
|
@@ -72,8 +72,7 @@ export class Duration {
|
|
|
72
72
|
return Duration.Ms(this.internal - another.internal);
|
|
73
73
|
}
|
|
74
74
|
times(factor) {
|
|
75
|
-
|
|
76
|
-
return Duration.Ms(rounding.round(this.internal * factor));
|
|
75
|
+
return Duration.Ms(new RoundingToNearestStrategy().round(this.internal * factor));
|
|
77
76
|
}
|
|
78
77
|
toAbsolute() {
|
|
79
78
|
return Duration.Ms(Math.abs(this.internal));
|
package/dist/height.vo.d.ts
CHANGED
|
@@ -11,8 +11,7 @@ export declare class Height {
|
|
|
11
11
|
static zero(): Height;
|
|
12
12
|
get(): number;
|
|
13
13
|
toMillimeters(): number;
|
|
14
|
-
toCentimeters(
|
|
15
|
-
format(rounding?: RoundingStrategy): string;
|
|
14
|
+
toCentimeters(): number;
|
|
16
15
|
toString(): string;
|
|
17
16
|
equals(another: Height): boolean;
|
|
18
17
|
greaterThan(another: Height): boolean;
|
package/dist/height.vo.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { HeightMillimeters } from "./height-milimiters.vo";
|
|
2
|
-
import { RoundingDecimalStrategy } from "./rounding-decimal.strategy";
|
|
3
2
|
import { RoundingToNearestStrategy } from "./rounding-to-nearest.strategy";
|
|
4
3
|
export class Height {
|
|
5
4
|
millimeters;
|
|
@@ -27,19 +26,11 @@ export class Height {
|
|
|
27
26
|
toMillimeters() {
|
|
28
27
|
return this.millimeters;
|
|
29
28
|
}
|
|
30
|
-
toCentimeters(
|
|
31
|
-
|
|
32
|
-
if (rounding)
|
|
33
|
-
return rounding.round(centimeters);
|
|
34
|
-
return centimeters;
|
|
35
|
-
}
|
|
36
|
-
format(rounding) {
|
|
37
|
-
const chosen = rounding ?? new RoundingDecimalStrategy(1);
|
|
38
|
-
const value = this.toCentimeters(chosen);
|
|
39
|
-
return `${value} cm`;
|
|
29
|
+
toCentimeters() {
|
|
30
|
+
return this.millimeters / Height.MILLIMETERS_PER_CENTIMETER;
|
|
40
31
|
}
|
|
41
32
|
toString() {
|
|
42
|
-
return this.
|
|
33
|
+
return this.millimeters.toString();
|
|
43
34
|
}
|
|
44
35
|
equals(another) {
|
|
45
36
|
return this.millimeters === another.millimeters;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
export const HourValueError = { Type: "hour.value.type", Invalid: "hour.value.invalid" };
|
|
3
|
+
// Stryker disable all
|
|
4
|
+
export const HourValue = z
|
|
5
|
+
// Stryker restore all
|
|
6
|
+
.number(HourValueError.Type)
|
|
7
|
+
.int(HourValueError.Type)
|
|
8
|
+
.gte(0, HourValueError.Invalid)
|
|
9
|
+
.lte(23, HourValueError.Invalid)
|
|
10
|
+
.brand("HourSchema");
|
package/dist/hour.vo.d.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type HourSchemaType } from "./hour-schema.vo";
|
|
1
|
+
import { type HourValueType } from "./hour-value.vo";
|
|
3
2
|
import { Timestamp } from "./timestamp.vo";
|
|
4
3
|
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
5
4
|
export declare class Hour {
|
|
6
5
|
private readonly value;
|
|
7
6
|
private constructor();
|
|
8
7
|
static fromValue(candidate: number): Hour;
|
|
9
|
-
static fromValueSafe(candidate:
|
|
8
|
+
static fromValueSafe(candidate: HourValueType): Hour;
|
|
10
9
|
static fromTimestamp(timestamp: Timestamp): Hour;
|
|
11
10
|
static fromTimestampValue(timestamp: TimestampValueType): Hour;
|
|
12
11
|
static zero(): Hour;
|
|
13
12
|
static max(): Hour;
|
|
14
|
-
get():
|
|
15
|
-
format(formatter: HourFormatter): string;
|
|
13
|
+
get(): HourValueType;
|
|
16
14
|
equals(another: Hour): boolean;
|
|
17
15
|
isAfter(another: Hour): boolean;
|
|
18
16
|
isBefore(another: Hour): boolean;
|
package/dist/hour.vo.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HourSchema } from "./hour-schema.vo";
|
|
1
|
+
import { HourValue } from "./hour-value.vo";
|
|
3
2
|
import { Timestamp } from "./timestamp.vo";
|
|
4
3
|
export class Hour {
|
|
5
4
|
value;
|
|
@@ -7,13 +6,13 @@ export class Hour {
|
|
|
7
6
|
this.value = value;
|
|
8
7
|
}
|
|
9
8
|
static fromValue(candidate) {
|
|
10
|
-
return new Hour(
|
|
9
|
+
return new Hour(HourValue.parse(candidate));
|
|
11
10
|
}
|
|
12
11
|
static fromValueSafe(candidate) {
|
|
13
12
|
return new Hour(candidate);
|
|
14
13
|
}
|
|
15
14
|
static fromTimestamp(timestamp) {
|
|
16
|
-
return new Hour(
|
|
15
|
+
return new Hour(HourValue.parse(new Date(timestamp.ms).getUTCHours()));
|
|
17
16
|
}
|
|
18
17
|
static fromTimestampValue(timestamp) {
|
|
19
18
|
return Hour.fromTimestamp(Timestamp.fromValue(timestamp));
|
|
@@ -27,9 +26,6 @@ export class Hour {
|
|
|
27
26
|
get() {
|
|
28
27
|
return this.value;
|
|
29
28
|
}
|
|
30
|
-
format(formatter) {
|
|
31
|
-
return formatter(this.value);
|
|
32
|
-
}
|
|
33
29
|
equals(another) {
|
|
34
30
|
return this.value === another.value;
|
|
35
31
|
}
|
|
@@ -43,7 +39,7 @@ export class Hour {
|
|
|
43
39
|
return Array.from({ length: 24 }, (_, index) => Hour.fromValue(index));
|
|
44
40
|
}
|
|
45
41
|
toString() {
|
|
46
|
-
return
|
|
42
|
+
return this.value.toString();
|
|
47
43
|
}
|
|
48
44
|
toJSON() {
|
|
49
45
|
return this.value;
|
package/dist/index.d.ts
CHANGED
|
@@ -30,8 +30,7 @@ export * from "./filename-from-string.vo";
|
|
|
30
30
|
export * from "./height.vo";
|
|
31
31
|
export * from "./height-milimiters.vo";
|
|
32
32
|
export * from "./hour.vo";
|
|
33
|
-
export * from "./hour-
|
|
34
|
-
export * from "./hour-schema.vo";
|
|
33
|
+
export * from "./hour-value.vo";
|
|
35
34
|
export * from "./iban.vo";
|
|
36
35
|
export * from "./iban-mask.service";
|
|
37
36
|
export * from "./iban-schema.vo";
|
|
@@ -50,7 +49,7 @@ export * from "./mime-value.vo";
|
|
|
50
49
|
export * from "./mimes";
|
|
51
50
|
export * from "./min-max-scaler.service";
|
|
52
51
|
export * from "./minute.vo";
|
|
53
|
-
export * from "./minute-
|
|
52
|
+
export * from "./minute-value.vo";
|
|
54
53
|
export * from "./money.vo";
|
|
55
54
|
export * from "./money-amount.vo";
|
|
56
55
|
export * from "./month.vo";
|
package/dist/index.js
CHANGED
|
@@ -30,8 +30,7 @@ export * from "./filename-from-string.vo";
|
|
|
30
30
|
export * from "./height.vo";
|
|
31
31
|
export * from "./height-milimiters.vo";
|
|
32
32
|
export * from "./hour.vo";
|
|
33
|
-
export * from "./hour-
|
|
34
|
-
export * from "./hour-schema.vo";
|
|
33
|
+
export * from "./hour-value.vo";
|
|
35
34
|
export * from "./iban.vo";
|
|
36
35
|
export * from "./iban-mask.service";
|
|
37
36
|
export * from "./iban-schema.vo";
|
|
@@ -50,7 +49,7 @@ export * from "./mime-value.vo";
|
|
|
50
49
|
export * from "./mimes";
|
|
51
50
|
export * from "./min-max-scaler.service";
|
|
52
51
|
export * from "./minute.vo";
|
|
53
|
-
export * from "./minute-
|
|
52
|
+
export * from "./minute-value.vo";
|
|
54
53
|
export * from "./money.vo";
|
|
55
54
|
export * from "./money-amount.vo";
|
|
56
55
|
export * from "./month.vo";
|
package/dist/mime-value.vo.d.ts
CHANGED
|
@@ -3,7 +3,4 @@ export declare const MimeValueError: {
|
|
|
3
3
|
Type: string;
|
|
4
4
|
Invalid: string;
|
|
5
5
|
};
|
|
6
|
-
export declare const MimeValue: z.core.$ZodBranded<z.
|
|
7
|
-
type: string;
|
|
8
|
-
subtype: string;
|
|
9
|
-
}, string>>, "MimeValue", "out">;
|
|
6
|
+
export declare const MimeValue: z.core.$ZodBranded<z.ZodString, "MimeValue", "out">;
|
package/dist/mime-value.vo.js
CHANGED
package/dist/mime.vo.d.ts
CHANGED
package/dist/mime.vo.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { MimeValue } from "./mime-value.vo";
|
|
2
|
-
export const MimeError = { NotAccepted: "mime.not.accepted" };
|
|
3
2
|
export class Mime {
|
|
4
3
|
type;
|
|
5
4
|
subtype;
|
|
@@ -8,7 +7,8 @@ export class Mime {
|
|
|
8
7
|
this.subtype = subtype;
|
|
9
8
|
}
|
|
10
9
|
static fromString(candidate) {
|
|
11
|
-
const
|
|
10
|
+
const value = MimeValue.parse(candidate.split(";")[0].trim());
|
|
11
|
+
const [type, subtype] = value.split("/");
|
|
12
12
|
return new Mime(type, subtype);
|
|
13
13
|
}
|
|
14
14
|
isSatisfiedBy(another) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
export const MinuteValueError = { Type: "minute.value.type", Invalid: "minute.value.invalid" };
|
|
3
|
+
// Stryker disable all
|
|
4
|
+
export const MinuteValue = z
|
|
5
|
+
// Stryker restore all
|
|
6
|
+
.number(MinuteValueError.Type)
|
|
7
|
+
.int(MinuteValueError.Type)
|
|
8
|
+
.gte(0, MinuteValueError.Invalid)
|
|
9
|
+
.lte(59, MinuteValueError.Invalid)
|
|
10
|
+
.brand("MinuteValue");
|
package/dist/minute.vo.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type MinuteValueType } from "./minute-value.vo";
|
|
2
2
|
import { Timestamp } from "./timestamp.vo";
|
|
3
3
|
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
4
4
|
export declare class Minute {
|
|
5
5
|
private readonly value;
|
|
6
6
|
private constructor();
|
|
7
7
|
static fromValue(candidate: number): Minute;
|
|
8
|
-
static fromValueSafe(candidate:
|
|
8
|
+
static fromValueSafe(candidate: MinuteValueType): Minute;
|
|
9
9
|
static fromTimestamp(timestamp: Timestamp): Minute;
|
|
10
10
|
static fromTimestampValue(timestamp: TimestampValueType): Minute;
|
|
11
11
|
static zero(): Minute;
|
|
12
12
|
static max(): Minute;
|
|
13
|
-
get():
|
|
13
|
+
get(): MinuteValueType;
|
|
14
14
|
equals(another: Minute): boolean;
|
|
15
15
|
isBefore(another: Minute): boolean;
|
|
16
16
|
isAfter(another: Minute): boolean;
|
package/dist/minute.vo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MinuteValue } from "./minute-value.vo";
|
|
2
2
|
import { Timestamp } from "./timestamp.vo";
|
|
3
3
|
export class Minute {
|
|
4
4
|
value;
|
|
@@ -6,13 +6,13 @@ export class Minute {
|
|
|
6
6
|
this.value = value;
|
|
7
7
|
}
|
|
8
8
|
static fromValue(candidate) {
|
|
9
|
-
return new Minute(
|
|
9
|
+
return new Minute(MinuteValue.parse(candidate));
|
|
10
10
|
}
|
|
11
11
|
static fromValueSafe(candidate) {
|
|
12
12
|
return new Minute(candidate);
|
|
13
13
|
}
|
|
14
14
|
static fromTimestamp(timestamp) {
|
|
15
|
-
return new Minute(
|
|
15
|
+
return new Minute(MinuteValue.parse(new Date(timestamp.ms).getUTCMinutes()));
|
|
16
16
|
}
|
|
17
17
|
static fromTimestampValue(timestamp) {
|
|
18
18
|
return Minute.fromTimestamp(Timestamp.fromValue(timestamp));
|
package/dist/money.vo.d.ts
CHANGED
|
@@ -7,22 +7,20 @@ export declare const MoneyError: {
|
|
|
7
7
|
};
|
|
8
8
|
export declare class Money {
|
|
9
9
|
private readonly amount;
|
|
10
|
-
private readonly rounding;
|
|
11
10
|
private static readonly ZERO;
|
|
12
11
|
private constructor();
|
|
13
|
-
static fromAmount(candidate: number
|
|
14
|
-
static fromAmountSafe(candidate: MoneyAmountType
|
|
12
|
+
static fromAmount(candidate: number): Money;
|
|
13
|
+
static fromAmountSafe(candidate: MoneyAmountType): Money;
|
|
15
14
|
static zero(): Money;
|
|
16
15
|
getAmount(): MoneyAmountType;
|
|
17
16
|
add(money: Money): Money;
|
|
18
|
-
multiply(factor: MultiplicationFactorType): Money;
|
|
17
|
+
multiply(factor: MultiplicationFactorType, rounding?: RoundingStrategy): Money;
|
|
19
18
|
subtract(money: Money): Money;
|
|
20
|
-
divide(factor: DivisionFactorType): Money;
|
|
19
|
+
divide(factor: DivisionFactorType, rounding?: RoundingStrategy): Money;
|
|
21
20
|
equals(another: Money): boolean;
|
|
22
21
|
isGreaterThan(another: Money): boolean;
|
|
23
22
|
isLessThan(another: Money): boolean;
|
|
24
23
|
isZero(): boolean;
|
|
25
|
-
format(): string;
|
|
26
24
|
toString(): string;
|
|
27
25
|
toJSON(): number;
|
|
28
26
|
}
|
package/dist/money.vo.js
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { MoneyAmount } from "./money-amount.vo";
|
|
2
|
-
import { RoundingDownStrategy } from "./rounding-down.strategy";
|
|
3
2
|
import { RoundingToNearestStrategy } from "./rounding-to-nearest.strategy";
|
|
4
3
|
export const MoneyError = { SubtractResultLessThanZero: "money.subtract.result.less.than.zero" };
|
|
5
4
|
export class Money {
|
|
6
5
|
amount;
|
|
7
|
-
rounding;
|
|
8
6
|
static ZERO = MoneyAmount.parse(0);
|
|
9
|
-
constructor(amount
|
|
7
|
+
constructor(amount) {
|
|
10
8
|
this.amount = amount;
|
|
11
|
-
this.rounding = rounding;
|
|
12
9
|
}
|
|
13
|
-
static fromAmount(candidate
|
|
14
|
-
return new Money(MoneyAmount.parse(candidate)
|
|
10
|
+
static fromAmount(candidate) {
|
|
11
|
+
return new Money(MoneyAmount.parse(candidate));
|
|
15
12
|
}
|
|
16
|
-
static fromAmountSafe(candidate
|
|
17
|
-
return new Money(candidate
|
|
13
|
+
static fromAmountSafe(candidate) {
|
|
14
|
+
return new Money(candidate);
|
|
18
15
|
}
|
|
19
16
|
static zero() {
|
|
20
17
|
return Money.fromAmount(0);
|
|
@@ -23,19 +20,19 @@ export class Money {
|
|
|
23
20
|
return this.amount;
|
|
24
21
|
}
|
|
25
22
|
add(money) {
|
|
26
|
-
return new Money(MoneyAmount.parse(this.amount + money.getAmount())
|
|
23
|
+
return new Money(MoneyAmount.parse(this.amount + money.getAmount()));
|
|
27
24
|
}
|
|
28
|
-
multiply(factor) {
|
|
29
|
-
return new Money(MoneyAmount.parse(
|
|
25
|
+
multiply(factor, rounding = new RoundingToNearestStrategy()) {
|
|
26
|
+
return new Money(MoneyAmount.parse(rounding.round(this.amount * factor)));
|
|
30
27
|
}
|
|
31
28
|
subtract(money) {
|
|
32
29
|
const result = this.amount - money.getAmount();
|
|
33
30
|
if (result < Money.ZERO)
|
|
34
31
|
throw new Error(MoneyError.SubtractResultLessThanZero);
|
|
35
|
-
return new Money(MoneyAmount.parse(
|
|
32
|
+
return new Money(MoneyAmount.parse(result));
|
|
36
33
|
}
|
|
37
|
-
divide(factor) {
|
|
38
|
-
return new Money(MoneyAmount.parse(
|
|
34
|
+
divide(factor, rounding = new RoundingToNearestStrategy()) {
|
|
35
|
+
return new Money(MoneyAmount.parse(rounding.round(this.amount / factor)));
|
|
39
36
|
}
|
|
40
37
|
equals(another) {
|
|
41
38
|
return this.amount === another.getAmount();
|
|
@@ -49,13 +46,8 @@ export class Money {
|
|
|
49
46
|
isZero() {
|
|
50
47
|
return this.amount === Money.ZERO;
|
|
51
48
|
}
|
|
52
|
-
format() {
|
|
53
|
-
const whole = new RoundingDownStrategy().round(this.amount / 100);
|
|
54
|
-
const fraction = this.amount % 100;
|
|
55
|
-
return `${whole}.${fraction.toString().padStart(2, "0")}`;
|
|
56
|
-
}
|
|
57
49
|
toString() {
|
|
58
|
-
return this.
|
|
50
|
+
return this.amount.toString();
|
|
59
51
|
}
|
|
60
52
|
toJSON() {
|
|
61
53
|
return this.amount;
|
package/dist/month.vo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { endOfMonth, format,
|
|
1
|
+
import { endOfMonth, format, startOfMonth } from "date-fns";
|
|
2
2
|
import { DateRange } from "./date-range.vo";
|
|
3
3
|
import { Integer } from "./integer.vo";
|
|
4
4
|
import { MonthIsoId } from "./month-iso-id.vo";
|
|
@@ -17,8 +17,8 @@ export class Month extends DateRange {
|
|
|
17
17
|
}
|
|
18
18
|
static fromIsoId(iso) {
|
|
19
19
|
const [year, month] = MonthIsoId.parse(iso).split("-").map(Number);
|
|
20
|
-
const reference =
|
|
21
|
-
return Month.fromTimestamp(
|
|
20
|
+
const reference = Timestamp.fromNumber(Date.UTC(year, month - 1, 1));
|
|
21
|
+
return Month.fromTimestamp(reference);
|
|
22
22
|
}
|
|
23
23
|
toIsoId() {
|
|
24
24
|
return MonthIsoId.parse(format(this.getStart().ms, "yyyy-MM"));
|
|
@@ -30,8 +30,8 @@ export class Month extends DateRange {
|
|
|
30
30
|
return this.shift(Integer.parse(1));
|
|
31
31
|
}
|
|
32
32
|
shift(count) {
|
|
33
|
-
const
|
|
34
|
-
return Month.fromTimestamp(Timestamp.fromNumber(
|
|
33
|
+
const start = new Date(this.getStart().ms);
|
|
34
|
+
return Month.fromTimestamp(Timestamp.fromNumber(Date.UTC(start.getUTCFullYear(), start.getUTCMonth() + count, 1)));
|
|
35
35
|
}
|
|
36
36
|
toString() {
|
|
37
37
|
return this.toIsoId();
|
|
@@ -3,9 +3,6 @@ export declare const PackageVersionSchemaError: {
|
|
|
3
3
|
Type: string;
|
|
4
4
|
BadChars: string;
|
|
5
5
|
};
|
|
6
|
-
export declare const
|
|
7
|
-
|
|
8
|
-
minor: number;
|
|
9
|
-
patch: number;
|
|
10
|
-
}, string>>, "PackageVersionSchema", "out">;
|
|
6
|
+
export declare const PACKAGE_VERSIONS_CHARS_WHITELIST: RegExp;
|
|
7
|
+
export declare const PackageVersionSchema: z.core.$ZodBranded<z.ZodString, "PackageVersionSchema", "out">;
|
|
11
8
|
export type PackageVersionSchemaType = z.infer<typeof PackageVersionSchema>;
|
|
@@ -4,14 +4,10 @@ export const PackageVersionSchemaError = {
|
|
|
4
4
|
BadChars: "package.version.schema.bad.chars",
|
|
5
5
|
};
|
|
6
6
|
// v, 1-4 digits, dot, 1-4 digits, dot, 1-4 digits - () for capturing groups
|
|
7
|
-
const PACKAGE_VERSIONS_CHARS_WHITELIST = /^v([0-9]{1,4})\.([0-9]{1,4})\.([0-9]{1,4})$/;
|
|
7
|
+
export const PACKAGE_VERSIONS_CHARS_WHITELIST = /^v([0-9]{1,4})\.([0-9]{1,4})\.([0-9]{1,4})$/;
|
|
8
8
|
// Stryker disable all
|
|
9
9
|
export const PackageVersionSchema = z
|
|
10
10
|
// Stryker restore all
|
|
11
11
|
.string(PackageVersionSchemaError.Type)
|
|
12
12
|
.regex(PACKAGE_VERSIONS_CHARS_WHITELIST, PackageVersionSchemaError.BadChars)
|
|
13
|
-
.transform((value) => {
|
|
14
|
-
const match = PACKAGE_VERSIONS_CHARS_WHITELIST.exec(value);
|
|
15
|
-
return { major: Number(match[1]), minor: Number(match[2]), patch: Number(match[3]) };
|
|
16
|
-
})
|
|
17
13
|
.brand("PackageVersionSchema");
|
|
@@ -3,7 +3,7 @@ export declare class PackageVersion {
|
|
|
3
3
|
private readonly major;
|
|
4
4
|
private readonly minor;
|
|
5
5
|
private readonly patch;
|
|
6
|
-
constructor(
|
|
6
|
+
private constructor();
|
|
7
7
|
static fromVersionString(candidate: string): PackageVersion;
|
|
8
8
|
static fromVersionStringSafe(candidate: PackageVersionSchemaType): PackageVersion;
|
|
9
9
|
static fromString(candidate: string): PackageVersion;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PackageVersionSchema } from "./package-version-schema.vo";
|
|
1
|
+
import { PACKAGE_VERSIONS_CHARS_WHITELIST, PackageVersionSchema, } from "./package-version-schema.vo";
|
|
2
2
|
export class PackageVersion {
|
|
3
3
|
major;
|
|
4
4
|
minor;
|
|
@@ -10,14 +10,15 @@ export class PackageVersion {
|
|
|
10
10
|
}
|
|
11
11
|
static fromVersionString(candidate) {
|
|
12
12
|
const version = PackageVersionSchema.parse(candidate);
|
|
13
|
-
return
|
|
13
|
+
return PackageVersion.fromVersionStringSafe(version);
|
|
14
14
|
}
|
|
15
15
|
static fromVersionStringSafe(candidate) {
|
|
16
|
-
|
|
16
|
+
const [, major, minor, patch] = PACKAGE_VERSIONS_CHARS_WHITELIST.exec(candidate).map(Number);
|
|
17
|
+
return new PackageVersion(major, minor, patch);
|
|
17
18
|
}
|
|
18
19
|
static fromString(candidate) {
|
|
19
20
|
const version = PackageVersionSchema.parse(`v${candidate}`);
|
|
20
|
-
return
|
|
21
|
+
return PackageVersion.fromVersionStringSafe(version);
|
|
21
22
|
}
|
|
22
23
|
compareTo(another) {
|
|
23
24
|
if (this.major > another.major)
|
package/dist/quarter.vo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { endOfQuarter, getQuarter, getYear,
|
|
1
|
+
import { endOfQuarter, getQuarter, getYear, startOfQuarter } from "date-fns";
|
|
2
2
|
import { DateRange } from "./date-range.vo";
|
|
3
3
|
import { QuarterIsoId } from "./quarter-iso-id.vo";
|
|
4
4
|
import { Timestamp } from "./timestamp.vo";
|
|
@@ -16,8 +16,7 @@ export class Quarter extends DateRange {
|
|
|
16
16
|
}
|
|
17
17
|
static fromIsoId(isoId) {
|
|
18
18
|
const [year, quarter] = QuarterIsoId.parse(isoId).split("-Q").map(Number);
|
|
19
|
-
|
|
20
|
-
return Quarter.fromTimestamp(Timestamp.fromNumber(reference));
|
|
19
|
+
return Quarter.fromTimestamp(Timestamp.fromNumber(Date.UTC(year, (quarter - 1) * 3, 1)));
|
|
21
20
|
}
|
|
22
21
|
toIsoId() {
|
|
23
22
|
const year = getYear(this.getStart().ms);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/age-years.vo.ts","../src/age.vo.ts","../src/api-key.vo.ts","../src/basename.vo.ts","../src/date-calculator.service.ts","../src/date-formatter.service.ts","../src/date-range.vo.ts","../src/day-iso-id.vo.ts","../src/day.vo.ts","../src/directory-path-absolute.vo.ts","../src/directory-path-relative.vo.ts","../src/distance-value.vo.ts","../src/distance.vo.ts","../src/division-factor.vo.ts","../src/dll.service.ts","../src/duration-ms.vo.ts","../src/duration.service.ts","../src/email-mask.service.ts","../src/email.vo.ts","../src/etags.vo.ts","../src/extension.vo.ts","../src/feature-flag-value.vo.ts","../src/feature-flag.vo.ts","../src/file-path-absolute-schema.vo.ts","../src/file-path-relative-schema.vo.ts","../src/file-path.vo.ts","../src/filename-affix.vo.ts","../src/filename-from-string.vo.ts","../src/filename.vo.ts","../src/height-milimiters.vo.ts","../src/height.vo.ts","../src/hour-
|
|
1
|
+
{"root":["../src/age-years.vo.ts","../src/age.vo.ts","../src/api-key.vo.ts","../src/basename.vo.ts","../src/date-calculator.service.ts","../src/date-formatter.service.ts","../src/date-range.vo.ts","../src/day-iso-id.vo.ts","../src/day.vo.ts","../src/directory-path-absolute.vo.ts","../src/directory-path-relative.vo.ts","../src/distance-value.vo.ts","../src/distance.vo.ts","../src/division-factor.vo.ts","../src/dll.service.ts","../src/duration-ms.vo.ts","../src/duration.service.ts","../src/email-mask.service.ts","../src/email.vo.ts","../src/etags.vo.ts","../src/extension.vo.ts","../src/feature-flag-value.vo.ts","../src/feature-flag.vo.ts","../src/file-path-absolute-schema.vo.ts","../src/file-path-relative-schema.vo.ts","../src/file-path.vo.ts","../src/filename-affix.vo.ts","../src/filename-from-string.vo.ts","../src/filename.vo.ts","../src/height-milimiters.vo.ts","../src/height.vo.ts","../src/hour-value.vo.ts","../src/hour.vo.ts","../src/iban-mask.service.ts","../src/iban-schema.vo.ts","../src/iban.vo.ts","../src/image.vo.ts","../src/index.ts","../src/integer-non-negative.vo.ts","../src/integer-positive.vo.ts","../src/integer.vo.ts","../src/language.vo.ts","../src/linear-regression.service.ts","../src/mean.service.ts","../src/mime-registry-entry.vo.ts","../src/mime-registry.service.ts","../src/mime-value.vo.ts","../src/mime.vo.ts","../src/mimes.ts","../src/min-max-scaler.service.ts","../src/minute-value.vo.ts","../src/minute.vo.ts","../src/money-amount.vo.ts","../src/money.vo.ts","../src/month-iso-id.vo.ts","../src/month.vo.ts","../src/multiplication-factor.vo.ts","../src/noop.service.ts","../src/object-key.vo.ts","../src/outlier-detector.service.ts","../src/package-version-schema.vo.ts","../src/package-version.vo.ts","../src/pagination-page.vo.ts","../src/pagination-skip.vo.ts","../src/pagination-take.vo.ts","../src/pagination.service.ts","../src/percentage.service.ts","../src/population-standard-deviation.service.ts","../src/quarter-iso-id.vo.ts","../src/quarter.vo.ts","../src/random.service.ts","../src/rate-limiter.service.ts","../src/relative-date.vo.ts","../src/reordering-item-position-value.vo.ts","../src/reordering.service.ts","../src/revision-value.vo.ts","../src/revision.vo.ts","../src/rounding-decimal.strategy.ts","../src/rounding-down.strategy.ts","../src/rounding-to-nearest.strategy.ts","../src/rounding-up.strategy.ts","../src/rounding.strategy.ts","../src/size-bytes.vo.ts","../src/size.vo.ts","../src/slug.service.ts","../src/sum.service.ts","../src/thousands-separator.service.ts","../src/time-zone-offset-value.vo.ts","../src/timestamp-value.vo.ts","../src/timestamp.vo.ts","../src/timezone.vo.ts","../src/ts-utils.ts","../src/url-with-slash.vo.ts","../src/url-without-slash.vo.ts","../src/visually-unambiguous-characters-generator.service.ts","../src/week-iso-id.vo.ts","../src/week.vo.ts","../src/weekday-iso-id.vo.ts","../src/weekday.vo.ts","../src/weight-grams.vo.ts","../src/weight.vo.ts","../src/year-iso-id.vo.ts","../src/year.vo.ts","../src/z-score.service.ts"],"version":"5.9.3"}
|
package/dist/week.vo.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { addWeeks, endOfISOWeek, getISOWeek, getISOWeekYear,
|
|
1
|
+
import { addWeeks, endOfISOWeek, getISOWeek, getISOWeekYear, startOfISOWeek } from "date-fns";
|
|
2
2
|
import { DateRange } from "./date-range.vo";
|
|
3
|
+
import { Duration } from "./duration.service";
|
|
3
4
|
import { Integer } from "./integer.vo";
|
|
4
5
|
import { Timestamp } from "./timestamp.vo";
|
|
5
6
|
import { WeekIsoId } from "./week-iso-id.vo";
|
|
@@ -18,8 +19,9 @@ export class Week extends DateRange {
|
|
|
18
19
|
static fromIsoId(isoId) {
|
|
19
20
|
const [year, week] = WeekIsoId.parse(isoId).split("-W").map(Number);
|
|
20
21
|
// ISO-8601 rule: Jan 4 is always in week 01 of the ISO week-year.
|
|
21
|
-
const
|
|
22
|
-
|
|
22
|
+
const januaryFourth = Timestamp.fromNumber(Date.UTC(year, 0, 4));
|
|
23
|
+
const firstWeekStart = Timestamp.fromNumber(startOfISOWeek(januaryFourth.ms).getTime());
|
|
24
|
+
return Week.fromTimestamp(firstWeekStart.add(Duration.Weeks(week - 1)));
|
|
23
25
|
}
|
|
24
26
|
toIsoId() {
|
|
25
27
|
const year = getISOWeekYear(this.getStart().ms);
|
|
@@ -5,6 +5,6 @@ export const WeekdayIsoId = z
|
|
|
5
5
|
// Stryker restore all
|
|
6
6
|
.number(WeekdayIsoIdError.Type)
|
|
7
7
|
.int(WeekdayIsoIdError.Type)
|
|
8
|
-
.min(
|
|
9
|
-
.max(
|
|
8
|
+
.min(1, WeekdayIsoIdError.Invalid)
|
|
9
|
+
.max(7, WeekdayIsoIdError.Invalid)
|
|
10
10
|
.brand("WeekdayIsoId");
|
package/dist/weekday.vo.d.ts
CHANGED
|
@@ -1,35 +1,21 @@
|
|
|
1
1
|
import { Timestamp } from "./timestamp.vo";
|
|
2
2
|
import type { TimestampValueType } from "./timestamp-value.vo";
|
|
3
|
-
|
|
4
|
-
export declare enum WeekdayFormatterEnum {
|
|
5
|
-
FULL = "FULL",// "Sunday"
|
|
6
|
-
SHORT = "SHORT",// "Sun"
|
|
7
|
-
ISO_NUMBER = "ISO_NUMBER",// Monday=1 ... Sunday=7
|
|
8
|
-
ZERO_BASED_NUMBER = "ZERO_BASED_NUMBER"
|
|
9
|
-
}
|
|
10
|
-
export declare const WeekdayValueError: {
|
|
11
|
-
Invalid: string;
|
|
12
|
-
};
|
|
13
|
-
export declare const WeekdayFormatters: Record<WeekdayFormatterEnum, WeekdayFormatter>;
|
|
3
|
+
import { type WeekdayIsoIdType } from "./weekday-iso-id.vo";
|
|
14
4
|
export declare class Weekday {
|
|
15
5
|
private readonly value;
|
|
16
|
-
private readonly formatter;
|
|
17
|
-
static readonly SUNDAY: Weekday;
|
|
18
6
|
static readonly MONDAY: Weekday;
|
|
19
7
|
static readonly TUESDAY: Weekday;
|
|
20
8
|
static readonly WEDNESDAY: Weekday;
|
|
21
9
|
static readonly THURSDAY: Weekday;
|
|
22
10
|
static readonly FRIDAY: Weekday;
|
|
23
11
|
static readonly SATURDAY: Weekday;
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
static readonly SUNDAY: Weekday;
|
|
13
|
+
private constructor();
|
|
14
|
+
static fromTimestamp(timestamp: Timestamp): Weekday;
|
|
26
15
|
static fromTimestampValue(timestamp: TimestampValueType): Weekday;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
toString(): string;
|
|
16
|
+
static fromIsoId(iso: WeekdayIsoIdType): Weekday;
|
|
17
|
+
get(): WeekdayIsoIdType;
|
|
30
18
|
equals(another: Weekday): boolean;
|
|
31
|
-
/** ISO-8601 weekday number: Monday=1 ... Sunday=7 */
|
|
32
|
-
toIsoNumber(): number;
|
|
33
19
|
isMonday(): boolean;
|
|
34
20
|
isTuesday(): boolean;
|
|
35
21
|
isWednesday(): boolean;
|
|
@@ -37,6 +23,6 @@ export declare class Weekday {
|
|
|
37
23
|
isFriday(): boolean;
|
|
38
24
|
isSaturday(): boolean;
|
|
39
25
|
isSunday(): boolean;
|
|
40
|
-
|
|
41
|
-
|
|
26
|
+
toJSON(): number;
|
|
27
|
+
toString(): string;
|
|
42
28
|
}
|
package/dist/weekday.vo.js
CHANGED
|
@@ -1,96 +1,59 @@
|
|
|
1
1
|
import { Timestamp } from "./timestamp.vo";
|
|
2
|
-
|
|
3
|
-
(function (WeekdayFormatterEnum) {
|
|
4
|
-
WeekdayFormatterEnum["FULL"] = "FULL";
|
|
5
|
-
WeekdayFormatterEnum["SHORT"] = "SHORT";
|
|
6
|
-
WeekdayFormatterEnum["ISO_NUMBER"] = "ISO_NUMBER";
|
|
7
|
-
WeekdayFormatterEnum["ZERO_BASED_NUMBER"] = "ZERO_BASED_NUMBER";
|
|
8
|
-
})(WeekdayFormatterEnum || (WeekdayFormatterEnum = {}));
|
|
9
|
-
export const WeekdayValueError = { Invalid: "weekday.invalid" };
|
|
10
|
-
const FULL_NAMES = [
|
|
11
|
-
"Sunday",
|
|
12
|
-
"Monday",
|
|
13
|
-
"Tuesday",
|
|
14
|
-
"Wednesday",
|
|
15
|
-
"Thursday",
|
|
16
|
-
"Friday",
|
|
17
|
-
"Saturday",
|
|
18
|
-
];
|
|
19
|
-
const SHORT_NAMES = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
20
|
-
export const WeekdayFormatters = {
|
|
21
|
-
FULL: (value) => FULL_NAMES[value],
|
|
22
|
-
SHORT: (value) => SHORT_NAMES[value],
|
|
23
|
-
ISO_NUMBER: (value) => (value === 0 ? 7 : value).toString(), // ISO-8601: Mon=1..Sun=7
|
|
24
|
-
ZERO_BASED_NUMBER: (value) => value.toString(), // JS getUTCDay(): Sun=0..Sat=6
|
|
25
|
-
};
|
|
2
|
+
import { WeekdayIsoId } from "./weekday-iso-id.vo";
|
|
26
3
|
export class Weekday {
|
|
27
|
-
// 0..6 (Sun..Sat)
|
|
28
4
|
value;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
static
|
|
32
|
-
static
|
|
33
|
-
static
|
|
34
|
-
static
|
|
35
|
-
static
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.formatter = formatter ?? WeekdayFormatters.FULL;
|
|
44
|
-
}
|
|
45
|
-
static fromTimestamp(timestamp, formatter) {
|
|
46
|
-
const dayZeroBased = new Date(timestamp.ms).getUTCDay(); // 0..6
|
|
47
|
-
return new Weekday(dayZeroBased, formatter);
|
|
5
|
+
static MONDAY = Weekday.fromIsoId(WeekdayIsoId.parse(1));
|
|
6
|
+
static TUESDAY = Weekday.fromIsoId(WeekdayIsoId.parse(2));
|
|
7
|
+
static WEDNESDAY = Weekday.fromIsoId(WeekdayIsoId.parse(3));
|
|
8
|
+
static THURSDAY = Weekday.fromIsoId(WeekdayIsoId.parse(4));
|
|
9
|
+
static FRIDAY = Weekday.fromIsoId(WeekdayIsoId.parse(5));
|
|
10
|
+
static SATURDAY = Weekday.fromIsoId(WeekdayIsoId.parse(6));
|
|
11
|
+
static SUNDAY = Weekday.fromIsoId(WeekdayIsoId.parse(7));
|
|
12
|
+
constructor(value) {
|
|
13
|
+
this.value = value;
|
|
14
|
+
}
|
|
15
|
+
static fromTimestamp(timestamp) {
|
|
16
|
+
// UTC returns numbers from 0-6, starting from Sunday
|
|
17
|
+
const utc = new Date(timestamp.ms).getUTCDay();
|
|
18
|
+
return new Weekday(WeekdayIsoId.parse(utc === 0 ? 7 : utc));
|
|
48
19
|
}
|
|
49
20
|
static fromTimestampValue(timestamp) {
|
|
50
21
|
return Weekday.fromTimestamp(Timestamp.fromValue(timestamp));
|
|
51
22
|
}
|
|
23
|
+
static fromIsoId(iso) {
|
|
24
|
+
return new Weekday(iso);
|
|
25
|
+
}
|
|
52
26
|
get() {
|
|
53
27
|
return this.value;
|
|
54
28
|
}
|
|
55
|
-
format() {
|
|
56
|
-
return this.formatter(this.value);
|
|
57
|
-
}
|
|
58
|
-
toString() {
|
|
59
|
-
return this.format();
|
|
60
|
-
}
|
|
61
29
|
equals(another) {
|
|
62
30
|
return this.value === another.value;
|
|
63
31
|
}
|
|
64
|
-
/** ISO-8601 weekday number: Monday=1 ... Sunday=7 */
|
|
65
|
-
toIsoNumber() {
|
|
66
|
-
return this.value === 0 ? 7 : this.value;
|
|
67
|
-
}
|
|
68
32
|
isMonday() {
|
|
69
|
-
return this.
|
|
33
|
+
return this.equals(Weekday.MONDAY);
|
|
70
34
|
}
|
|
71
35
|
isTuesday() {
|
|
72
|
-
return this.
|
|
36
|
+
return this.equals(Weekday.TUESDAY);
|
|
73
37
|
}
|
|
74
38
|
isWednesday() {
|
|
75
|
-
return this.
|
|
39
|
+
return this.equals(Weekday.WEDNESDAY);
|
|
76
40
|
}
|
|
77
41
|
isThursday() {
|
|
78
|
-
return this.
|
|
42
|
+
return this.equals(Weekday.THURSDAY);
|
|
79
43
|
}
|
|
80
44
|
isFriday() {
|
|
81
|
-
return this.
|
|
45
|
+
return this.equals(Weekday.FRIDAY);
|
|
82
46
|
}
|
|
83
47
|
isSaturday() {
|
|
84
|
-
return this.
|
|
48
|
+
return this.equals(Weekday.SATURDAY);
|
|
85
49
|
}
|
|
86
50
|
isSunday() {
|
|
87
|
-
return this.
|
|
51
|
+
return this.equals(Weekday.SUNDAY);
|
|
88
52
|
}
|
|
89
|
-
|
|
90
|
-
return
|
|
53
|
+
toJSON() {
|
|
54
|
+
return this.value;
|
|
91
55
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return [...rest, Sunday];
|
|
56
|
+
toString() {
|
|
57
|
+
return this.value.toString();
|
|
95
58
|
}
|
|
96
59
|
}
|
package/dist/year.vo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { endOfYear, getYear, startOfYear } from "date-fns";
|
|
2
2
|
import { DateRange } from "./date-range.vo";
|
|
3
3
|
import { Integer } from "./integer.vo";
|
|
4
4
|
import { Timestamp } from "./timestamp.vo";
|
|
@@ -19,8 +19,8 @@ export class Year extends DateRange {
|
|
|
19
19
|
return Year.fromIsoId(YearIsoId.parse(String(candidate)));
|
|
20
20
|
}
|
|
21
21
|
static fromIsoId(isoId) {
|
|
22
|
-
const
|
|
23
|
-
return Year.
|
|
22
|
+
const year = Number(isoId);
|
|
23
|
+
return new Year(Timestamp.fromNumber(Date.UTC(year, 0, 1)), Timestamp.fromNumber(Date.UTC(year + 1, 0, 1) - 1));
|
|
24
24
|
}
|
|
25
25
|
toIsoId() {
|
|
26
26
|
return YearIsoId.parse(String(getYear(this.getStart().ms)));
|
|
@@ -40,8 +40,8 @@ export class Year extends DateRange {
|
|
|
40
40
|
return this.shift(Integer.parse(1));
|
|
41
41
|
}
|
|
42
42
|
shift(count) {
|
|
43
|
-
const
|
|
44
|
-
return Year.
|
|
43
|
+
const year = getYear(this.getStart().ms) + count;
|
|
44
|
+
return Year.fromIsoId(YearIsoId.parse(String(year)));
|
|
45
45
|
}
|
|
46
46
|
toString() {
|
|
47
47
|
return this.toIsoId();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bgord/tools",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Bartosz Gordon",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@commitlint/cli": "20.4.1",
|
|
25
25
|
"@commitlint/config-conventional": "20.4.1",
|
|
26
26
|
"@stryker-mutator/core": "9.5.1",
|
|
27
|
-
"@types/bun": "1.3.
|
|
27
|
+
"@types/bun": "1.3.9",
|
|
28
28
|
"cspell": "9.6.4",
|
|
29
29
|
"knip": "5.83.1",
|
|
30
30
|
"lefthook": "2.1.0",
|
package/readme.md
CHANGED
|
@@ -55,8 +55,7 @@ src/
|
|
|
55
55
|
├── filename.vo.ts
|
|
56
56
|
├── height-milimiters.vo.ts
|
|
57
57
|
├── height.vo.ts
|
|
58
|
-
├── hour-
|
|
59
|
-
├── hour-schema.vo.ts
|
|
58
|
+
├── hour-value.vo.ts
|
|
60
59
|
├── hour.vo.ts
|
|
61
60
|
├── iban-mask.service.ts
|
|
62
61
|
├── iban-schema.vo.ts
|
|
@@ -74,7 +73,7 @@ src/
|
|
|
74
73
|
├── mime.vo.ts
|
|
75
74
|
├── mimes.ts
|
|
76
75
|
├── min-max-scaler.service.ts
|
|
77
|
-
├── minute-
|
|
76
|
+
├── minute-value.vo.ts
|
|
78
77
|
├── minute.vo.ts
|
|
79
78
|
├── money-amount.vo.ts
|
|
80
79
|
├── money.vo.ts
|
|
@@ -1,10 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,19 +0,0 @@
|
|
|
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 suffix = value < 12 ? "a.m." : "p.m.";
|
|
14
|
-
const twelveHourValue = value % 12 || 12;
|
|
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-schema.vo.d.ts
DELETED
package/dist/hour-schema.vo.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as z from "zod/v4";
|
|
2
|
-
export const HourSchemaError = { Type: "hour.schema.type", Invalid: "hour.schema.invalid" };
|
|
3
|
-
// Stryker disable all
|
|
4
|
-
export const HourSchema = z
|
|
5
|
-
// Stryker restore all
|
|
6
|
-
.number(HourSchemaError.Type)
|
|
7
|
-
.int(HourSchemaError.Type)
|
|
8
|
-
.gte(0, HourSchemaError.Invalid)
|
|
9
|
-
.lte(23, HourSchemaError.Invalid)
|
|
10
|
-
.brand("HourSchema");
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import * as z from "zod/v4";
|
|
2
|
-
export declare const MinuteSchemaError: {
|
|
3
|
-
Type: string;
|
|
4
|
-
Invalid: string;
|
|
5
|
-
};
|
|
6
|
-
export declare const MinuteSchema: z.core.$ZodBranded<z.ZodNumber, "MinuteSchema", "out">;
|
|
7
|
-
export type MinuteSchemaType = z.infer<typeof MinuteSchema>;
|
package/dist/minute-schema.vo.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as z from "zod/v4";
|
|
2
|
-
export const MinuteSchemaError = { Type: "minute.schema.error", Invalid: "minute.schema.invalid" };
|
|
3
|
-
// Stryker disable all
|
|
4
|
-
export const MinuteSchema = z
|
|
5
|
-
// Stryker restore all
|
|
6
|
-
.number(MinuteSchemaError.Type)
|
|
7
|
-
.int(MinuteSchemaError.Type)
|
|
8
|
-
.gte(0, MinuteSchemaError.Invalid)
|
|
9
|
-
.lte(59, MinuteSchemaError.Invalid)
|
|
10
|
-
.brand("MinuteSchema");
|