@bgord/tools 1.3.13 → 1.3.15

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.
Files changed (62) hide show
  1. package/dist/age-years.vo.js +2 -2
  2. package/dist/age.vo.d.ts +1 -1
  3. package/dist/age.vo.js +1 -1
  4. package/dist/date-range.vo.d.ts +3 -1
  5. package/dist/date-range.vo.js +4 -1
  6. package/dist/day.vo.d.ts +1 -1
  7. package/dist/day.vo.js +3 -3
  8. package/dist/distance.vo.d.ts +1 -2
  9. package/dist/distance.vo.js +3 -6
  10. package/dist/dll.service.d.ts +2 -2
  11. package/dist/duration.service.js +1 -2
  12. package/dist/height.vo.d.ts +1 -2
  13. package/dist/height.vo.js +3 -12
  14. package/dist/hour-value.vo.d.ts +7 -0
  15. package/dist/hour-value.vo.js +10 -0
  16. package/dist/hour.vo.d.ts +4 -6
  17. package/dist/hour.vo.js +4 -8
  18. package/dist/index.d.ts +3 -3
  19. package/dist/index.js +3 -3
  20. package/dist/linear-regression.service.d.ts +1 -1
  21. package/dist/mean.service.d.ts +1 -1
  22. package/dist/mime-registry-entry.vo.d.ts +2 -2
  23. package/dist/mime-registry.service.d.ts +1 -1
  24. package/dist/mime-value.vo.d.ts +1 -4
  25. package/dist/mime-value.vo.js +0 -1
  26. package/dist/mime.vo.d.ts +0 -3
  27. package/dist/mime.vo.js +2 -2
  28. package/dist/min-max-scaler.service.d.ts +1 -1
  29. package/dist/minute-value.vo.d.ts +7 -0
  30. package/dist/minute-value.vo.js +10 -0
  31. package/dist/minute.vo.d.ts +4 -4
  32. package/dist/minute.vo.js +3 -3
  33. package/dist/money.vo.d.ts +4 -6
  34. package/dist/money.vo.js +12 -20
  35. package/dist/month.vo.js +5 -5
  36. package/dist/outlier-detector.service.d.ts +1 -1
  37. package/dist/package-version-schema.vo.d.ts +2 -5
  38. package/dist/package-version-schema.vo.js +1 -5
  39. package/dist/package-version.vo.d.ts +1 -1
  40. package/dist/package-version.vo.js +5 -4
  41. package/dist/pagination.service.d.ts +2 -2
  42. package/dist/population-standard-deviation.service.d.ts +1 -1
  43. package/dist/quarter.vo.js +2 -3
  44. package/dist/reordering.service.d.ts +2 -2
  45. package/dist/sum.service.d.ts +2 -2
  46. package/dist/ts-utils.d.ts +1 -1
  47. package/dist/tsconfig.tsbuildinfo +1 -1
  48. package/dist/week.vo.js +5 -3
  49. package/dist/weekday-iso-id.vo.d.ts +7 -0
  50. package/dist/weekday-iso-id.vo.js +10 -0
  51. package/dist/weekday.vo.d.ts +8 -22
  52. package/dist/weekday.vo.js +29 -66
  53. package/dist/year.vo.js +5 -5
  54. package/dist/z-score.service.d.ts +1 -1
  55. package/package.json +2 -2
  56. package/readme.md +3 -3
  57. package/dist/hour-format.service.d.ts +0 -10
  58. package/dist/hour-format.service.js +0 -19
  59. package/dist/hour-schema.vo.d.ts +0 -7
  60. package/dist/hour-schema.vo.js +0 -10
  61. package/dist/minute-schema.vo.d.ts +0 -7
  62. package/dist/minute-schema.vo.js +0 -10
@@ -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: 1, max: 130 };
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(1, AgeYearsError.Invalid)
9
+ .min(0, AgeYearsError.Invalid)
10
10
  .max(130, AgeYearsError.Invalid)
11
11
  .brand("AgeYears");
package/dist/age.vo.d.ts CHANGED
@@ -18,7 +18,7 @@ export declare class Age {
18
18
  birthdate: string;
19
19
  now: Timestamp;
20
20
  }): Age;
21
- get(): number;
21
+ get(): AgeYearsType;
22
22
  equals(other: Age): boolean;
23
23
  isOlderThan(other: Age): boolean;
24
24
  isYoungerThan(other: Age): boolean;
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.fromNumber(new Date(candidate.birthdate).getTime());
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));
@@ -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
- toRange(): [Timestamp, Timestamp];
12
+ get(): [Timestamp, Timestamp];
13
+ getDuration(): Duration;
12
14
  contains(timestamp: Timestamp): boolean;
13
15
  equals(other: DateRange): boolean;
14
16
  toString(): string;
@@ -14,9 +14,12 @@ export class DateRange {
14
14
  getEnd() {
15
15
  return this.end;
16
16
  }
17
- toRange() {
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
  }
@@ -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(money: Distance): Distance;
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
  }
@@ -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(money) {
29
- const result = this.value - money.get();
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.format();
47
+ return this.value.toString();
51
48
  }
52
49
  toJSON() {
53
50
  return this.value;
@@ -23,7 +23,7 @@ export declare class DoublyLinkedList<T> {
23
23
  insertBefore(node: Node<T>, target: Node<T>): void;
24
24
  find(callback: (node: Node<T>) => boolean): Node<T> | null;
25
25
  reverse(): void;
26
- toArray(): Node<T>[];
27
- static fromArray<T>(array: T[]): DoublyLinkedList<T>;
26
+ toArray(): ReadonlyArray<Node<T>>;
27
+ static fromArray<T>(array: ReadonlyArray<T>): DoublyLinkedList<T>;
28
28
  [Symbol.iterator](): IterableIterator<Node<T>>;
29
29
  }
@@ -72,8 +72,7 @@ export class Duration {
72
72
  return Duration.Ms(this.internal - another.internal);
73
73
  }
74
74
  times(factor) {
75
- const rounding = new RoundingToNearestStrategy();
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));
@@ -11,8 +11,7 @@ export declare class Height {
11
11
  static zero(): Height;
12
12
  get(): number;
13
13
  toMillimeters(): number;
14
- toCentimeters(rounding?: RoundingStrategy): number;
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(rounding) {
31
- const centimeters = this.millimeters / Height.MILLIMETERS_PER_CENTIMETER;
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.format(new RoundingDecimalStrategy(1));
33
+ return this.millimeters.toString();
43
34
  }
44
35
  equals(another) {
45
36
  return this.millimeters === another.millimeters;
@@ -0,0 +1,7 @@
1
+ import * as z from "zod/v4";
2
+ export declare const HourValueError: {
3
+ Type: string;
4
+ Invalid: string;
5
+ };
6
+ export declare const HourValue: z.core.$ZodBranded<z.ZodNumber, "HourSchema", "out">;
7
+ export type HourValueType = z.infer<typeof HourValue>;
@@ -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,22 +1,20 @@
1
- import { type HourFormatter } from "./hour-format.service";
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: HourSchemaType): Hour;
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(): HourSchemaType;
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;
19
- static list(): readonly Hour[];
17
+ static list(): ReadonlyArray<Hour>;
20
18
  toString(): string;
21
19
  toJSON(): number;
22
20
  }
package/dist/hour.vo.js CHANGED
@@ -1,5 +1,4 @@
1
- import { HourFormatters } from "./hour-format.service";
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(HourSchema.parse(candidate));
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(HourSchema.parse(new Date(timestamp.ms).getUTCHours()));
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 HourFormatters.TWENTY_FOUR_HOURS(this.value);
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-format.service";
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-schema.vo";
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";
@@ -97,6 +96,7 @@ export * from "./visually-unambiguous-characters-generator.service";
97
96
  export * from "./week.vo";
98
97
  export * from "./week-iso-id.vo";
99
98
  export * from "./weekday.vo";
99
+ export * from "./weekday-iso-id.vo";
100
100
  export * from "./weight.vo";
101
101
  export * from "./weight-grams.vo";
102
102
  export * from "./year.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-format.service";
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-schema.vo";
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";
@@ -97,6 +96,7 @@ export * from "./visually-unambiguous-characters-generator.service";
97
96
  export * from "./week.vo";
98
97
  export * from "./week-iso-id.vo";
99
98
  export * from "./weekday.vo";
99
+ export * from "./weekday-iso-id.vo";
100
100
  export * from "./weight.vo";
101
101
  export * from "./weight-grams.vo";
102
102
  export * from "./year.vo";
@@ -21,7 +21,7 @@ export declare class LinearRegression {
21
21
  private readonly params;
22
22
  private readonly rounding;
23
23
  constructor(params: LinearRegressionParamsType, rounding?: RoundingStrategy);
24
- static fromPairs(pairs: LinearRegressionPairType[], rounding?: RoundingStrategy): LinearRegression;
24
+ static fromPairs(pairs: ReadonlyArray<LinearRegressionPairType>, rounding?: RoundingStrategy): LinearRegression;
25
25
  predict(x: LinearRegressionPairType["x"], rounding?: RoundingStrategy): LinearRegressionPredictionType;
26
26
  inspect(): LinearRegression["params"];
27
27
  }
@@ -4,5 +4,5 @@ export declare const MeanError: {
4
4
  };
5
5
  export declare class Mean {
6
6
  private static readonly DEFAULT_ROUNDING;
7
- static calculate(values: number[], rounding?: RoundingStrategy): number;
7
+ static calculate(values: ReadonlyArray<number>, rounding?: RoundingStrategy): number;
8
8
  }
@@ -2,6 +2,6 @@ import type { ExtensionType } from "./extension.vo";
2
2
  import type { Mime } from "./mime.vo";
3
3
  export declare class MimeRegistryEntry {
4
4
  readonly mime: Mime;
5
- readonly extensions: ExtensionType[];
6
- constructor(mime: Mime, extensions: ExtensionType[]);
5
+ readonly extensions: ReadonlyArray<ExtensionType>;
6
+ constructor(mime: Mime, extensions: ReadonlyArray<ExtensionType>);
7
7
  }
@@ -8,7 +8,7 @@ export declare const MimeRegistryError: {
8
8
  export declare class MimeRegistry {
9
9
  private readonly byExtension;
10
10
  private readonly byMime;
11
- constructor(entries: readonly MimeRegistryEntry[]);
11
+ constructor(entries: ReadonlyArray<MimeRegistryEntry>);
12
12
  hasExtension(extension: ExtensionType): boolean;
13
13
  hasMime(mime: Mime): boolean;
14
14
  fromExtension(extension: ExtensionType): Mime | undefined;
@@ -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.ZodPipe<z.ZodString, z.ZodTransform<{
7
- type: string;
8
- subtype: string;
9
- }, string>>, "MimeValue", "out">;
6
+ export declare const MimeValue: z.core.$ZodBranded<z.ZodString, "MimeValue", "out">;
@@ -7,5 +7,4 @@ export const MimeValue = z
7
7
  // Stryker restore all
8
8
  .string(MimeValueError.Type)
9
9
  .regex(MIME_VALUE_CHARS_WHITELIST, MimeValueError.Invalid)
10
- .transform((value) => ({ type: value.split("/")[0], subtype: value.split("/")[1] }))
11
10
  .brand("MimeValue");
package/dist/mime.vo.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- export declare const MimeError: {
2
- NotAccepted: string;
3
- };
4
1
  export declare class Mime {
5
2
  readonly type: string;
6
3
  readonly subtype: string;
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 { type, subtype } = MimeValue.parse(candidate.split(";")[0].trim());
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) {
@@ -38,7 +38,7 @@ export declare class MinMaxScaler {
38
38
  constructor(config: MinMaxScalerConfigType);
39
39
  scale(value: MinMaxScalerValueType): ScaleResult;
40
40
  descale(scaled: MinMaxScalerValueType): DescaleResult;
41
- static getMinMax(values: MinMaxScalerValueType[]): {
41
+ static getMinMax(values: ReadonlyArray<MinMaxScalerValueType>): {
42
42
  min: number;
43
43
  max: number;
44
44
  };
@@ -0,0 +1,7 @@
1
+ import * as z from "zod/v4";
2
+ export declare const MinuteValueError: {
3
+ Type: string;
4
+ Invalid: string;
5
+ };
6
+ export declare const MinuteValue: z.core.$ZodBranded<z.ZodNumber, "MinuteValue", "out">;
7
+ export type MinuteValueType = z.infer<typeof MinuteValue>;
@@ -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");
@@ -1,20 +1,20 @@
1
- import { type MinuteSchemaType } from "./minute-schema.vo";
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: MinuteSchemaType): Minute;
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(): MinuteSchemaType;
13
+ get(): MinuteValueType;
14
14
  equals(another: Minute): boolean;
15
15
  isBefore(another: Minute): boolean;
16
16
  isAfter(another: Minute): boolean;
17
- static list(): readonly Minute[];
17
+ static list(): ReadonlyArray<Minute>;
18
18
  toString(): string;
19
19
  toJSON(): number;
20
20
  }
package/dist/minute.vo.js CHANGED
@@ -1,4 +1,4 @@
1
- import { MinuteSchema } from "./minute-schema.vo";
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(MinuteSchema.parse(candidate));
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(MinuteSchema.parse(new Date(timestamp.ms).getUTCMinutes()));
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));
@@ -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, rounding?: RoundingStrategy): Money;
14
- static fromAmountSafe(candidate: MoneyAmountType, rounding?: RoundingStrategy): Money;
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, rounding = new RoundingToNearestStrategy()) {
7
+ constructor(amount) {
10
8
  this.amount = amount;
11
- this.rounding = rounding;
12
9
  }
13
- static fromAmount(candidate, rounding) {
14
- return new Money(MoneyAmount.parse(candidate), rounding);
10
+ static fromAmount(candidate) {
11
+ return new Money(MoneyAmount.parse(candidate));
15
12
  }
16
- static fromAmountSafe(candidate, rounding) {
17
- return new Money(candidate, rounding);
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()), this.rounding);
23
+ return new Money(MoneyAmount.parse(this.amount + money.getAmount()));
27
24
  }
28
- multiply(factor) {
29
- return new Money(MoneyAmount.parse(this.rounding.round(this.amount * factor)), this.rounding);
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(this.rounding.round(result)), this.rounding);
32
+ return new Money(MoneyAmount.parse(result));
36
33
  }
37
- divide(factor) {
38
- return new Money(MoneyAmount.parse(this.rounding.round(this.amount / factor)), this.rounding);
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.format();
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, getMonth, setMonth, startOfMonth } from "date-fns";
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 = setMonth(Date.UTC(year), month - 1).getTime();
21
- return Month.fromTimestamp(Timestamp.fromNumber(reference));
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 shifted = setMonth(this.getStart().ms, getMonth(this.getStart().ms) + count).getTime();
34
- return Month.fromTimestamp(Timestamp.fromNumber(shifted));
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();
@@ -4,6 +4,6 @@ export declare const OutlierDetectorError: {
4
4
  export declare class OutlierDetector {
5
5
  private readonly zScore;
6
6
  private readonly threshold;
7
- constructor(values: number[], threshold: number);
7
+ constructor(values: ReadonlyArray<number>, threshold: number);
8
8
  isInlier(value: number): boolean;
9
9
  }
@@ -3,9 +3,6 @@ export declare const PackageVersionSchemaError: {
3
3
  Type: string;
4
4
  BadChars: string;
5
5
  };
6
- export declare const PackageVersionSchema: z.core.$ZodBranded<z.ZodPipe<z.ZodString, z.ZodTransform<{
7
- major: number;
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(major: number, minor: number, patch: number);
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 new PackageVersion(version.major, version.minor, version.patch);
13
+ return PackageVersion.fromVersionStringSafe(version);
14
14
  }
15
15
  static fromVersionStringSafe(candidate) {
16
- return new PackageVersion(candidate.major, candidate.minor, candidate.patch);
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 new PackageVersion(version.major, version.minor, version.patch);
21
+ return PackageVersion.fromVersionStringSafe(version);
21
22
  }
22
23
  compareTo(another) {
23
24
  if (this.major > another.major)
@@ -18,7 +18,7 @@ export type PaginationExhaustedConfig = {
18
18
  export type PaginationPrepareConfigType<T> = {
19
19
  total: TotalType;
20
20
  pagination: PaginationType;
21
- result: T[];
21
+ result: ReadonlyArray<T>;
22
22
  };
23
23
  export declare class Pagination {
24
24
  static parse(values: PaginationValuesType, _take: TakeType): PaginationType;
@@ -41,7 +41,7 @@ export declare class Pagination {
41
41
  }): PaginationType;
42
42
  }
43
43
  export type Paged<T> = {
44
- result: T[];
44
+ result: ReadonlyArray<T>;
45
45
  meta: {
46
46
  exhausted: ExhaustedType;
47
47
  currentPage: PageType;
@@ -3,5 +3,5 @@ export declare const PopulationStandardDeviationError: {
3
3
  NotEnoughValues: string;
4
4
  };
5
5
  export declare class PopulationStandardDeviation {
6
- static calculate(values: number[], rounding?: RoundingStrategy): number;
6
+ static calculate(values: ReadonlyArray<number>, rounding?: RoundingStrategy): number;
7
7
  }
@@ -1,4 +1,4 @@
1
- import { endOfQuarter, getQuarter, getYear, setQuarter, startOfQuarter } from "date-fns";
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
- const reference = setQuarter(Date.UTC(year), quarter).getTime();
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);
@@ -44,7 +44,7 @@ export declare class ReorderingTransfer {
44
44
  export declare class ReorderingCalculator {
45
45
  private dll;
46
46
  constructor();
47
- static fromArray(ids: ReorderingItem["id"][]): ReorderingCalculator;
47
+ static fromArray(ids: ReadonlyArray<ReorderingItem["id"]>): ReorderingCalculator;
48
48
  add(id: ReorderingItem["id"]): ReorderingItem;
49
49
  delete(id: ReorderingItem["id"]): void;
50
50
  transfer(transfer: ReorderingTransfer): ReturnType<ReorderingCalculator["read"]>;
@@ -55,7 +55,7 @@ export declare class ReorderingCalculator {
55
55
  private recalculate;
56
56
  }
57
57
  export declare class ReorderingIntegrator {
58
- static appendPosition(reordering: ReorderingType[]): <T extends {
58
+ static appendPosition(reordering: ReadonlyArray<ReorderingType>): <T extends {
59
59
  id: ReorderingItemIdType;
60
60
  }>(item: T) => WithReorderingPositionValue<T>;
61
61
  static sortByPosition(): (a: WithReorderingPositionValue<unknown>, b: WithReorderingPositionValue<unknown>) => number;
@@ -1,4 +1,4 @@
1
1
  export declare class Sum {
2
- static of(values: readonly number[]): number;
3
- static precise(values: readonly number[]): number;
2
+ static of(values: ReadonlyArray<number>): number;
3
+ static precise(values: ReadonlyArray<number>): number;
4
4
  }
@@ -1,3 +1,3 @@
1
- export type Constructor<T> = new (...args: any[]) => T;
1
+ export type Constructor<T> = new (...args: ReadonlyArray<any>) => T;
2
2
  export type Falsy<T> = T | null | undefined;
3
3
  export type Nullable<T> = T | null;
@@ -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-format.service.ts","../src/hour-schema.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-schema.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.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"}
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, setISOWeek, startOfISOWeek } from "date-fns";
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 reference = setISOWeek(Date.UTC(year, 0, 4), week).getTime();
22
- return Week.fromTimestamp(Timestamp.fromNumber(reference));
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);
@@ -0,0 +1,7 @@
1
+ import * as z from "zod/v4";
2
+ export declare const WeekdayIsoIdError: {
3
+ Type: string;
4
+ Invalid: string;
5
+ };
6
+ export declare const WeekdayIsoId: z.core.$ZodBranded<z.ZodNumber, "WeekdayIsoId", "out">;
7
+ export type WeekdayIsoIdType = z.infer<typeof WeekdayIsoId>;
@@ -0,0 +1,10 @@
1
+ import * as z from "zod/v4";
2
+ export const WeekdayIsoIdError = { Type: "weekday.iso.id.type", Invalid: "weekday.iso.id.invalid" };
3
+ // Stryker disable all
4
+ export const WeekdayIsoId = z
5
+ // Stryker restore all
6
+ .number(WeekdayIsoIdError.Type)
7
+ .int(WeekdayIsoIdError.Type)
8
+ .min(1, WeekdayIsoIdError.Invalid)
9
+ .max(7, WeekdayIsoIdError.Invalid)
10
+ .brand("WeekdayIsoId");
@@ -1,35 +1,21 @@
1
1
  import { Timestamp } from "./timestamp.vo";
2
2
  import type { TimestampValueType } from "./timestamp-value.vo";
3
- export type WeekdayFormatter = (value: Weekday["value"]) => string;
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
- constructor(candidate: number, formatter?: WeekdayFormatter);
25
- static fromTimestamp(timestamp: Timestamp, formatter?: WeekdayFormatter): Weekday;
12
+ static readonly SUNDAY: Weekday;
13
+ private constructor();
14
+ static fromTimestamp(timestamp: Timestamp): Weekday;
26
15
  static fromTimestampValue(timestamp: TimestampValueType): Weekday;
27
- get(): number;
28
- format(): string;
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
- static list(formatter?: WeekdayFormatter): readonly Weekday[];
41
- static listMondayFirst(formatter?: WeekdayFormatter): readonly Weekday[];
26
+ toJSON(): number;
27
+ toString(): string;
42
28
  }
@@ -1,96 +1,59 @@
1
1
  import { Timestamp } from "./timestamp.vo";
2
- export var WeekdayFormatterEnum;
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
- // default formatter used by toString()/format() when no runtime formatter given
30
- formatter;
31
- static SUNDAY = new Weekday(0);
32
- static MONDAY = new Weekday(1);
33
- static TUESDAY = new Weekday(2);
34
- static WEDNESDAY = new Weekday(3);
35
- static THURSDAY = new Weekday(4);
36
- static FRIDAY = new Weekday(5);
37
- static SATURDAY = new Weekday(6);
38
- constructor(candidate, formatter) {
39
- if (!Number.isInteger(candidate) || candidate < 0 || candidate > 6) {
40
- throw new Error(WeekdayValueError.Invalid);
41
- }
42
- this.value = candidate;
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.value === 1;
33
+ return this.equals(Weekday.MONDAY);
70
34
  }
71
35
  isTuesday() {
72
- return this.value === 2;
36
+ return this.equals(Weekday.TUESDAY);
73
37
  }
74
38
  isWednesday() {
75
- return this.value === 3;
39
+ return this.equals(Weekday.WEDNESDAY);
76
40
  }
77
41
  isThursday() {
78
- return this.value === 4;
42
+ return this.equals(Weekday.THURSDAY);
79
43
  }
80
44
  isFriday() {
81
- return this.value === 5;
45
+ return this.equals(Weekday.FRIDAY);
82
46
  }
83
47
  isSaturday() {
84
- return this.value === 6;
48
+ return this.equals(Weekday.SATURDAY);
85
49
  }
86
50
  isSunday() {
87
- return this.value === 0;
51
+ return this.equals(Weekday.SUNDAY);
88
52
  }
89
- static list(formatter) {
90
- return Array.from({ length: 7 }, (_, index) => new Weekday(index, formatter));
53
+ toJSON() {
54
+ return this.value;
91
55
  }
92
- static listMondayFirst(formatter) {
93
- const [Sunday, ...rest] = Weekday.list(formatter);
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 { addYears, endOfYear, getYear, startOfYear } from "date-fns";
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 reference = Date.UTC(Number(isoId));
23
- return Year.fromTimestamp(Timestamp.fromNumber(reference));
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 shifted = addYears(this.getStart().ms, count).getTime();
44
- return Year.fromTimestamp(Timestamp.fromNumber(shifted));
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();
@@ -6,6 +6,6 @@ export declare class ZScore {
6
6
  private readonly rounding;
7
7
  private readonly mean;
8
8
  private readonly standardDeviation;
9
- constructor(values: number[], rounding?: RoundingStrategy);
9
+ constructor(values: ReadonlyArray<number>, rounding?: RoundingStrategy);
10
10
  calculate(value: number): number;
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/tools",
3
- "version": "1.3.13",
3
+ "version": "1.3.15",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Bartosz Gordon",
@@ -26,7 +26,7 @@
26
26
  "@stryker-mutator/core": "9.5.1",
27
27
  "@types/bun": "1.3.8",
28
28
  "cspell": "9.6.4",
29
- "knip": "5.83.0",
29
+ "knip": "5.83.1",
30
30
  "lefthook": "2.1.0",
31
31
  "lockfile-lint": "5.0.0",
32
32
  "only-allow": "1.2.2",
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-format.service.ts
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-schema.vo.ts
76
+ ├── minute-value.vo.ts
78
77
  ├── minute.vo.ts
79
78
  ├── money-amount.vo.ts
80
79
  ├── money.vo.ts
@@ -121,6 +120,7 @@ src/
121
120
  ├── visually-unambiguous-characters-generator.service.ts
122
121
  ├── week-iso-id.vo.ts
123
122
  ├── week.vo.ts
123
+ ├── weekday-iso-id.vo.ts
124
124
  ├── weekday.vo.ts
125
125
  ├── weight-grams.vo.ts
126
126
  ├── weight.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
- };
@@ -1,7 +0,0 @@
1
- import * as z from "zod/v4";
2
- export declare const HourSchemaError: {
3
- Type: string;
4
- Invalid: string;
5
- };
6
- export declare const HourSchema: z.core.$ZodBranded<z.ZodNumber, "HourSchema", "out">;
7
- export type HourSchemaType = z.infer<typeof HourSchema>;
@@ -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>;
@@ -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");