@bgord/tools 1.2.20 → 1.2.21

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 (106) hide show
  1. package/package.json +2 -3
  2. package/src/age-years.vo.ts +0 -16
  3. package/src/age.vo.ts +0 -60
  4. package/src/api-key.vo.ts +0 -16
  5. package/src/basename.vo.ts +0 -33
  6. package/src/clock-format.service.ts +0 -15
  7. package/src/clock.vo.ts +0 -55
  8. package/src/date-calculator.service.ts +0 -18
  9. package/src/date-formatter.service.ts +0 -21
  10. package/src/date-range.vo.ts +0 -36
  11. package/src/day-iso-id.vo.ts +0 -21
  12. package/src/day.vo.ts +0 -59
  13. package/src/directory-path-absolute.vo.ts +0 -36
  14. package/src/directory-path-relative.vo.ts +0 -34
  15. package/src/distance-value.vo.ts +0 -13
  16. package/src/distance.vo.ts +0 -76
  17. package/src/division-factor.vo.ts +0 -12
  18. package/src/dll.service.ts +0 -177
  19. package/src/duration-ms.vo.ts +0 -9
  20. package/src/duration.service.ts +0 -94
  21. package/src/email-mask.service.ts +0 -17
  22. package/src/email.vo.ts +0 -9
  23. package/src/etags.vo.ts +0 -47
  24. package/src/extension.vo.ts +0 -27
  25. package/src/feature-flag-value.vo.ts +0 -12
  26. package/src/feature-flag.vo.ts +0 -11
  27. package/src/file-path-absolute-schema.vo.ts +0 -34
  28. package/src/file-path-relative-schema.vo.ts +0 -34
  29. package/src/file-path.vo.ts +0 -100
  30. package/src/filename-affix.vo.ts +0 -27
  31. package/src/filename-from-string.vo.ts +0 -27
  32. package/src/filename.vo.ts +0 -92
  33. package/src/height-milimiters.vo.ts +0 -16
  34. package/src/height.vo.ts +0 -79
  35. package/src/hour-format.service.ts +0 -22
  36. package/src/hour-schema.vo.ts +0 -14
  37. package/src/hour.vo.ts +0 -64
  38. package/src/iban-mask.service.ts +0 -18
  39. package/src/iban-schema.vo.ts +0 -17
  40. package/src/iban.vo.ts +0 -28
  41. package/src/image.vo.ts +0 -28
  42. package/src/index.ts +0 -105
  43. package/src/integer-non-negative.vo.ts +0 -16
  44. package/src/integer-positive.vo.ts +0 -13
  45. package/src/integer.vo.ts +0 -9
  46. package/src/language.vo.ts +0 -13
  47. package/src/linear-regression.service.ts +0 -73
  48. package/src/mean.service.ts +0 -18
  49. package/src/mime-types.vo.ts +0 -7
  50. package/src/mime-value.vo.ts +0 -14
  51. package/src/mime.vo.ts +0 -50
  52. package/src/min-max-scaler.service.ts +0 -96
  53. package/src/minute-schema.vo.ts +0 -14
  54. package/src/minute.vo.ts +0 -59
  55. package/src/money-amount.vo.ts +0 -13
  56. package/src/money.vo.ts +0 -83
  57. package/src/month-iso-id.vo.ts +0 -24
  58. package/src/month.vo.ts +0 -53
  59. package/src/multiplication-factor.vo.ts +0 -15
  60. package/src/noop.service.ts +0 -3
  61. package/src/notification-template.vo.ts +0 -10
  62. package/src/object-key.vo.ts +0 -36
  63. package/src/outlier-detector.service.ts +0 -21
  64. package/src/package-version-schema.vo.ts +0 -23
  65. package/src/package-version.vo.ts +0 -66
  66. package/src/pagination-page.vo.ts +0 -11
  67. package/src/pagination-skip.vo.ts +0 -10
  68. package/src/pagination-take.vo.ts +0 -10
  69. package/src/pagination.service.ts +0 -73
  70. package/src/percentage.service.ts +0 -15
  71. package/src/population-standard-deviation.service.ts +0 -23
  72. package/src/quarter-iso-id.vo.ts +0 -15
  73. package/src/quarter.vo.ts +0 -41
  74. package/src/random.service.ts +0 -19
  75. package/src/rate-limiter.service.ts +0 -30
  76. package/src/relative-date.vo.ts +0 -21
  77. package/src/reordering-item-position-value.vo.ts +0 -10
  78. package/src/reordering.service.ts +0 -163
  79. package/src/revision-value.vo.ts +0 -10
  80. package/src/revision.vo.ts +0 -44
  81. package/src/rounding-decimal.strategy.ts +0 -25
  82. package/src/rounding-down.strategy.ts +0 -7
  83. package/src/rounding-to-nearest.strategy.ts +0 -7
  84. package/src/rounding-up.strategy.ts +0 -7
  85. package/src/rounding.strategy.ts +0 -3
  86. package/src/size-bytes.vo.ts +0 -13
  87. package/src/size.vo.ts +0 -113
  88. package/src/slug.service.ts +0 -18
  89. package/src/sum.service.ts +0 -19
  90. package/src/thousands-separator.service.ts +0 -10
  91. package/src/time-zone-offset-value.vo.ts +0 -21
  92. package/src/timestamp-value.vo.ts +0 -13
  93. package/src/timestamp.vo.ts +0 -66
  94. package/src/timezone.vo.ts +0 -26
  95. package/src/ts-utils.ts +0 -3
  96. package/src/url-with-slash.vo.ts +0 -12
  97. package/src/url-without-slash.vo.ts +0 -12
  98. package/src/visually-unambiguous-characters-generator.service.ts +0 -39
  99. package/src/week-iso-id.vo.ts +0 -28
  100. package/src/week.vo.ts +0 -57
  101. package/src/weekday.vo.ts +0 -119
  102. package/src/weight-grams.vo.ts +0 -13
  103. package/src/weight.vo.ts +0 -91
  104. package/src/year-iso-id.vo.ts +0 -15
  105. package/src/year.vo.ts +0 -63
  106. package/src/z-score.service.ts +0 -25
@@ -1,92 +0,0 @@
1
- import { Basename, type BasenameType } from "./basename.vo";
2
- import { Extension, type ExtensionType } from "./extension.vo";
3
- import { FilenameAffix, FilenameAffixStrategy, type FilenameAffixType } from "./filename-affix.vo";
4
- import { FilenameFromString } from "./filename-from-string.vo";
5
- import { Mime } from "./mime.vo";
6
-
7
- export class Filename {
8
- private constructor(
9
- private readonly basename: BasenameType,
10
- private readonly extension: ExtensionType,
11
- ) {}
12
-
13
- static fromParts(basename: string, extension: string): Filename {
14
- return new Filename(Basename.parse(basename), Extension.parse(extension));
15
- }
16
-
17
- static fromPartsSafe(basename: BasenameType, extension: ExtensionType): Filename {
18
- return new Filename(basename, extension);
19
- }
20
-
21
- static fromString(candidate: string): Filename {
22
- const filename = FilenameFromString.parse(candidate);
23
-
24
- return new Filename(filename.basename, filename.extension);
25
- }
26
-
27
- get(): string {
28
- return `${this.basename}.${this.extension}`;
29
- }
30
-
31
- getBasename(): BasenameType {
32
- return this.basename;
33
- }
34
-
35
- getExtension(): ExtensionType {
36
- return this.extension;
37
- }
38
-
39
- getMime(): Mime {
40
- return Mime.fromExtension(this.extension);
41
- }
42
-
43
- withExtension(extension: ExtensionType): Filename {
44
- return new Filename(this.basename, extension);
45
- }
46
-
47
- withBasename(basename: BasenameType): Filename {
48
- return new Filename(basename, this.extension);
49
- }
50
-
51
- withAffix(candidate: string, strategy: FilenameAffixStrategy): Filename {
52
- const affix = FilenameAffix.parse(candidate);
53
-
54
- if (strategy === FilenameAffixStrategy.prefix) {
55
- return new Filename(Basename.parse(`${affix}${this.basename}`), this.extension);
56
- }
57
-
58
- return new Filename(Basename.parse(`${this.basename}${affix}`), this.extension);
59
- }
60
-
61
- withAffixSafe(affix: FilenameAffixType, strategy: FilenameAffixStrategy): Filename {
62
- if (strategy === FilenameAffixStrategy.prefix) {
63
- return new Filename(Basename.parse(`${affix}${this.basename}`), this.extension);
64
- }
65
-
66
- return new Filename(Basename.parse(`${this.basename}${affix}`), this.extension);
67
- }
68
-
69
- withSuffix(candidate: string) {
70
- return this.withAffix(candidate, FilenameAffixStrategy.suffix);
71
- }
72
-
73
- withSuffixSafe(affix: FilenameAffixType): Filename {
74
- return this.withAffix(affix, FilenameAffixStrategy.suffix);
75
- }
76
-
77
- withPrefix(candidate: string) {
78
- return this.withAffix(candidate, FilenameAffixStrategy.prefix);
79
- }
80
-
81
- withPrefixSafe(affix: FilenameAffixType): Filename {
82
- return this.withAffix(affix, FilenameAffixStrategy.prefix);
83
- }
84
-
85
- toString(): string {
86
- return this.get();
87
- }
88
-
89
- toJSON(): string {
90
- return this.get();
91
- }
92
- }
@@ -1,16 +0,0 @@
1
- import { z } from "zod/v4";
2
-
3
- export const HeightMillimetersError = {
4
- Type: "height.millimeters.type",
5
- Invalid: "height.millimeters.invalid",
6
- };
7
-
8
- // Stryker disable all
9
- export const HeightMillimeters = z
10
- // Stryker restore all
11
- .number(HeightMillimetersError.Type)
12
- .int(HeightMillimetersError.Type)
13
- .min(0, HeightMillimetersError.Invalid)
14
- .brand("HeightMillimeters");
15
-
16
- export type HeightMillimetersType = z.infer<typeof HeightMillimeters>;
package/src/height.vo.ts DELETED
@@ -1,79 +0,0 @@
1
- import { HeightMillimeters, type HeightMillimetersType } from "./height-milimiters.vo";
2
- import type { RoundingStrategy } from "./rounding.strategy";
3
- import { RoundingDecimalStrategy } from "./rounding-decimal.strategy";
4
- import { RoundingToNearestStrategy } from "./rounding-to-nearest.strategy";
5
-
6
- export class Height {
7
- private static readonly ZERO = HeightMillimeters.parse(0);
8
-
9
- private static readonly MILLIMETERS_PER_CENTIMETER = 10;
10
-
11
- private constructor(private readonly millimeters: HeightMillimetersType) {}
12
-
13
- static fromMillimeters(millimeters: number): Height {
14
- return new Height(HeightMillimeters.parse(millimeters));
15
- }
16
-
17
- static fromMillimetersSafe(millimeters: HeightMillimetersType): Height {
18
- return new Height(millimeters);
19
- }
20
-
21
- static fromCentimeters(
22
- centimeters: number,
23
- rounding: RoundingStrategy = new RoundingToNearestStrategy(),
24
- ): Height {
25
- const millimeters = rounding.round(centimeters * Height.MILLIMETERS_PER_CENTIMETER);
26
-
27
- return new Height(HeightMillimeters.parse(millimeters));
28
- }
29
-
30
- static zero(): Height {
31
- return Height.fromMillimetersSafe(Height.ZERO);
32
- }
33
-
34
- get(): number {
35
- return this.millimeters;
36
- }
37
-
38
- toMillimeters(): number {
39
- return this.millimeters;
40
- }
41
-
42
- toCentimeters(rounding?: RoundingStrategy): number {
43
- const centimeters = this.millimeters / Height.MILLIMETERS_PER_CENTIMETER;
44
-
45
- if (rounding) return rounding.round(centimeters);
46
- return centimeters;
47
- }
48
-
49
- format(rounding?: RoundingStrategy): string {
50
- const chosen = rounding ?? new RoundingDecimalStrategy(1);
51
- const value = this.toCentimeters(chosen);
52
-
53
- return `${value} cm`;
54
- }
55
-
56
- toString(): string {
57
- return this.format(new RoundingDecimalStrategy(1));
58
- }
59
-
60
- equals(another: Height): boolean {
61
- return this.millimeters === another.millimeters;
62
- }
63
-
64
- greaterThan(another: Height): boolean {
65
- return this.millimeters > another.millimeters;
66
- }
67
-
68
- lessThan(another: Height): boolean {
69
- return this.millimeters < another.millimeters;
70
- }
71
-
72
- isZero(): boolean {
73
- return this.millimeters === 0;
74
- }
75
-
76
- toJSON(): number {
77
- return this.millimeters;
78
- }
79
- }
@@ -1,22 +0,0 @@
1
- export type HourFormatter = (value: number) => string;
2
-
3
- enum HourFormatterEnum {
4
- TWENTY_FOUR_HOURS = "TWENTY_FOUR_HOURS",
5
- TWENTY_FOUR_HOURS_WO_PADDING = "TWENTY_FOUR_HOURS_WO_PADDING",
6
- AM_PM = "AM_PM",
7
- TWELVE_HOURS = "TWELVE_HOURS",
8
- TWELVE_HOURS_WO_PADDING = "TWELVE_HOURS_WO_PADDING",
9
- }
10
-
11
- export const HourFormatters: Record<HourFormatterEnum, HourFormatter> = {
12
- TWENTY_FOUR_HOURS: (value) => value.toString().padStart(2, "0"),
13
- TWENTY_FOUR_HOURS_WO_PADDING: (value) => value.toString(),
14
- AM_PM: (value) => {
15
- const suffix = value < 12 ? "a.m." : "p.m.";
16
- const twelveHourValue = value % 12 || 12;
17
-
18
- return `${twelveHourValue} ${suffix}`;
19
- },
20
- TWELVE_HOURS: (value) => (value % 12 || 12).toString().padStart(2, "0"),
21
- TWELVE_HOURS_WO_PADDING: (value) => (value % 12 || 12).toString(),
22
- };
@@ -1,14 +0,0 @@
1
- import { z } from "zod/v4";
2
-
3
- export const HourSchemaError = { Type: "hour.schema.type", Invalid: "hour.schema.invalid" };
4
-
5
- // Stryker disable all
6
- export const HourSchema = z
7
- // Stryker restore all
8
- .number(HourSchemaError.Type)
9
- .int(HourSchemaError.Type)
10
- .gte(0, HourSchemaError.Invalid)
11
- .lte(23, HourSchemaError.Invalid)
12
- .brand("HourSchema");
13
-
14
- export type HourSchemaType = z.infer<typeof HourSchema>;
package/src/hour.vo.ts DELETED
@@ -1,64 +0,0 @@
1
- import { type HourFormatter, HourFormatters } from "./hour-format.service";
2
- import { HourSchema, type HourSchemaType } from "./hour-schema.vo";
3
- import { Timestamp } from "./timestamp.vo";
4
- import type { TimestampValueType } from "./timestamp-value.vo";
5
-
6
- export class Hour {
7
- private constructor(private readonly value: HourSchemaType) {}
8
-
9
- static fromValue(candidate: number): Hour {
10
- return new Hour(HourSchema.parse(candidate));
11
- }
12
-
13
- static fromValueSafe(candidate: HourSchemaType) {
14
- return new Hour(candidate);
15
- }
16
-
17
- static fromTimestamp(timestamp: Timestamp): Hour {
18
- return new Hour(HourSchema.parse(new Date(timestamp.ms).getUTCHours()));
19
- }
20
-
21
- static fromTimestampValue(timestamp: TimestampValueType): Hour {
22
- return Hour.fromTimestamp(Timestamp.fromValue(timestamp));
23
- }
24
-
25
- static zero(): Hour {
26
- return Hour.fromValue(0);
27
- }
28
-
29
- static max(): Hour {
30
- return Hour.fromValue(23);
31
- }
32
-
33
- get(): HourSchemaType {
34
- return this.value;
35
- }
36
-
37
- format(formatter: HourFormatter): string {
38
- return formatter(this.value);
39
- }
40
-
41
- equals(another: Hour): boolean {
42
- return this.value === another.value;
43
- }
44
-
45
- isAfter(another: Hour): boolean {
46
- return this.value > another.value;
47
- }
48
-
49
- isBefore(another: Hour): boolean {
50
- return this.value < another.value;
51
- }
52
-
53
- static list(): readonly Hour[] {
54
- return Array.from({ length: 24 }, (_, index) => Hour.fromValue(index));
55
- }
56
-
57
- toString(): string {
58
- return HourFormatters.TWENTY_FOUR_HOURS(this.value);
59
- }
60
-
61
- toJSON(): number {
62
- return this.value;
63
- }
64
- }
@@ -1,18 +0,0 @@
1
- import type { IBAN } from "./iban.vo";
2
-
3
- export class IbanMask {
4
- static censor(iban: IBAN): string {
5
- const value = iban.format();
6
-
7
- const FIRST_SPACE_INDEX = 4;
8
- const LAST_SPACE_INDEX = value.length - 5;
9
-
10
- const start = value.slice(0, FIRST_SPACE_INDEX);
11
- const middle = value.slice(FIRST_SPACE_INDEX + 1, LAST_SPACE_INDEX);
12
- const end = value.slice(-4);
13
-
14
- const maskedMiddle = middle.replace(/[A-Z0-9]/g, "*");
15
-
16
- return `${start} ${maskedMiddle} ${end}`;
17
- }
18
- }
@@ -1,17 +0,0 @@
1
- import { z } from "zod/v4";
2
-
3
- export const IbanSchemaError = { Type: "iban.schema.type", Invalid: "iban.schema.invalid" };
4
-
5
- // Two letters for country code, two digits, 11–30 uppercase letters or digits
6
- const IBAN_CHARS_WHITELIST = /^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$/;
7
-
8
- // Stryker disable all
9
- export const IbanSchema = z
10
- // Stryker restore all
11
- .string(IbanSchemaError.Type)
12
- .toUpperCase()
13
- .transform((value) => value.replaceAll(" ", ""))
14
- .refine((value) => IBAN_CHARS_WHITELIST.test(value), IbanSchemaError.Invalid)
15
- .brand("IbanSchema");
16
-
17
- export type IbanSchemaType = z.infer<typeof IbanSchema>;
package/src/iban.vo.ts DELETED
@@ -1,28 +0,0 @@
1
- import { IbanSchema, type IbanSchemaType } from "./iban-schema.vo";
2
-
3
- export class IBAN {
4
- private readonly value: IbanSchemaType;
5
-
6
- constructor(candidate: string) {
7
- this.value = IbanSchema.parse(candidate);
8
- }
9
-
10
- toString(): IbanSchemaType {
11
- return this.value;
12
- }
13
-
14
- format(): string {
15
- // (.{4}) - capture any four characters
16
- // (?=.) - positive lookahead, at least one more character after the match
17
- // "$1 " - replace each match with the group and a space
18
- return this.value.replace(/(.{4})(?=.)/g, "$1 ");
19
- }
20
-
21
- get countryCode(): string {
22
- return this.value.slice(0, 2);
23
- }
24
-
25
- equals(other: IBAN): boolean {
26
- return this.value === other.value;
27
- }
28
- }
package/src/image.vo.ts DELETED
@@ -1,28 +0,0 @@
1
- import { z } from "zod/v4";
2
-
3
- export const ImageWidthError = { Type: "image.width.type", Length: "image.width.length" };
4
- export const ImageHeightError = { Type: "image.height.type", Length: "image.height.length" };
5
-
6
- const IMAGE_DIMENSIONS_CONSTRAINTS = { min: 1, max: 10_000 };
7
-
8
- // Stryker disable all
9
- export const ImageWidth = z
10
- // Stryker restore all
11
- .number(ImageWidthError.Type)
12
- .int(ImageWidthError.Type)
13
- .min(IMAGE_DIMENSIONS_CONSTRAINTS.min, ImageWidthError.Length)
14
- .max(IMAGE_DIMENSIONS_CONSTRAINTS.max, ImageWidthError.Length)
15
- .brand("ImageWidth");
16
-
17
- export type ImageWidthType = z.infer<typeof ImageWidth>;
18
-
19
- // Stryker disable all
20
- export const ImageHeight = z
21
- // Stryker restore all
22
- .number(ImageHeightError.Type)
23
- .int(ImageHeightError.Type)
24
- .min(IMAGE_DIMENSIONS_CONSTRAINTS.min, ImageHeightError.Length)
25
- .max(IMAGE_DIMENSIONS_CONSTRAINTS.max, ImageHeightError.Length)
26
- .brand("ImageHeight");
27
-
28
- export type ImageHeightType = z.infer<typeof ImageHeight>;
package/src/index.ts DELETED
@@ -1,105 +0,0 @@
1
- export * from "./age.vo";
2
- export * from "./age-years.vo";
3
- export * from "./api-key.vo";
4
- export * from "./basename.vo";
5
- export * from "./clock.vo";
6
- export * from "./clock-format.service";
7
- export * from "./date-calculator.service";
8
- export * from "./date-formatter.service";
9
- export * from "./date-range.vo";
10
- export * from "./day.vo";
11
- export * from "./day-iso-id.vo";
12
- export * from "./directory-path-absolute.vo";
13
- export * from "./directory-path-relative.vo";
14
- export * from "./distance.vo";
15
- export * from "./distance-value.vo";
16
- export * from "./division-factor.vo";
17
- export * from "./dll.service";
18
- export * from "./duration.service";
19
- export * from "./duration-ms.vo";
20
- export * from "./email.vo";
21
- export * from "./email-mask.service";
22
- export * from "./etags.vo";
23
- export * from "./extension.vo";
24
- export * from "./feature-flag.vo";
25
- export * from "./feature-flag-value.vo";
26
- export * from "./file-path.vo";
27
- export * from "./file-path-absolute-schema.vo";
28
- export * from "./file-path-relative-schema.vo";
29
- export * from "./filename.vo";
30
- export * from "./filename-affix.vo";
31
- export * from "./filename-from-string.vo";
32
- export * from "./height.vo";
33
- export * from "./height-milimiters.vo";
34
- export * from "./hour.vo";
35
- export * from "./hour-format.service";
36
- export * from "./hour-schema.vo";
37
- export * from "./iban.vo";
38
- export * from "./iban-mask.service";
39
- export * from "./iban-schema.vo";
40
- export * from "./image.vo";
41
- export * from "./index";
42
- export * from "./integer.vo";
43
- export * from "./integer-non-negative.vo";
44
- export * from "./integer-positive.vo";
45
- export * from "./language.vo";
46
- export * from "./linear-regression.service";
47
- export * from "./mean.service";
48
- export * from "./mime.vo";
49
- export * from "./mime-types.vo";
50
- export * from "./mime-value.vo";
51
- export * from "./min-max-scaler.service";
52
- export * from "./minute.vo";
53
- export * from "./minute-schema.vo";
54
- export * from "./money.vo";
55
- export * from "./money-amount.vo";
56
- export * from "./month.vo";
57
- export * from "./month-iso-id.vo";
58
- export * from "./multiplication-factor.vo";
59
- export * from "./noop.service";
60
- export * from "./notification-template.vo";
61
- export * from "./object-key.vo";
62
- export * from "./outlier-detector.service";
63
- export * from "./package-version.vo";
64
- export * from "./package-version-schema.vo";
65
- export * from "./pagination.service";
66
- export * from "./pagination-page.vo";
67
- export * from "./pagination-skip.vo";
68
- export * from "./pagination-take.vo";
69
- export * from "./percentage.service";
70
- export * from "./population-standard-deviation.service";
71
- export * from "./quarter.vo";
72
- export * from "./quarter-iso-id.vo";
73
- export * from "./random.service";
74
- export * from "./rate-limiter.service";
75
- export * from "./relative-date.vo";
76
- export * from "./reordering.service";
77
- export * from "./reordering-item-position-value.vo";
78
- export * from "./revision.vo";
79
- export * from "./revision-value.vo";
80
- export * from "./rounding.strategy";
81
- export * from "./rounding-decimal.strategy";
82
- export * from "./rounding-down.strategy";
83
- export * from "./rounding-to-nearest.strategy";
84
- export * from "./rounding-up.strategy";
85
- export * from "./size.vo";
86
- export * from "./size-bytes.vo";
87
- export * from "./slug.service";
88
- export * from "./sum.service";
89
- export * from "./thousands-separator.service";
90
- export * from "./time-zone-offset-value.vo";
91
- export * from "./timestamp.vo";
92
- export * from "./timestamp-value.vo";
93
- export * from "./timezone.vo";
94
- export * from "./ts-utils";
95
- export * from "./url-with-slash.vo";
96
- export * from "./url-without-slash.vo";
97
- export * from "./visually-unambiguous-characters-generator.service";
98
- export * from "./week.vo";
99
- export * from "./week-iso-id.vo";
100
- export * from "./weekday.vo";
101
- export * from "./weight.vo";
102
- export * from "./weight-grams.vo";
103
- export * from "./year.vo";
104
- export * from "./year-iso-id.vo";
105
- export * from "./z-score.service";
@@ -1,16 +0,0 @@
1
- import { z } from "zod/v4";
2
-
3
- export const IntegerNonNegativeError = {
4
- Type: "integer.non.negative.type",
5
- Invalid: "integer.non.negative.invalid",
6
- };
7
-
8
- // Stryker disable all
9
- export const IntegerNonNegative = z
10
- // Stryker restore all
11
- .number(IntegerNonNegativeError.Type)
12
- .int(IntegerNonNegativeError.Type)
13
- .min(0, IntegerNonNegativeError.Invalid)
14
- .brand("IntegerNonNegative");
15
-
16
- export type IntegerNonNegativeType = z.infer<typeof IntegerNonNegative>;
@@ -1,13 +0,0 @@
1
- import { z } from "zod/v4";
2
-
3
- export const IntegerPositiveError = { Type: "integer.positive.type", Invalid: "integer.positive.invalid" };
4
-
5
- // Stryker disable all
6
- export const IntegerPositive = z
7
- // Stryker restore all
8
- .number(IntegerPositiveError.Type)
9
- .int(IntegerPositiveError.Type)
10
- .min(1, IntegerPositiveError.Invalid)
11
- .brand("IntegerPositive");
12
-
13
- export type IntegerPositiveType = z.infer<typeof IntegerPositive>;
package/src/integer.vo.ts DELETED
@@ -1,9 +0,0 @@
1
- import { z } from "zod/v4";
2
-
3
- export const IntegerError = { Type: "integer.type" };
4
-
5
- // Stryker disable all
6
- export const Integer = z.number(IntegerError.Type).int(IntegerError.Type).brand("Integer");
7
- // Stryker restore all
8
-
9
- export type IntegerType = z.infer<typeof Integer>;
@@ -1,13 +0,0 @@
1
- import { z } from "zod/v4";
2
-
3
- export const LanguageError = { Type: "language.type", BadChars: "language.bad.chars" };
4
-
5
- // Two lowercase letters
6
- const LANGUAGE_CHARS_WHITELIST = /^[a-z]{2}$/;
7
-
8
- export const Language = z
9
- .string(LanguageError.Type)
10
- .toLowerCase()
11
- .regex(LANGUAGE_CHARS_WHITELIST, LanguageError.BadChars);
12
-
13
- export type LanguageType = z.infer<typeof Language>;
@@ -1,73 +0,0 @@
1
- import type { RoundingStrategy } from "./rounding.strategy";
2
- import { RoundingToNearestStrategy } from "./rounding-to-nearest.strategy";
3
-
4
- export type LinearRegressionPairType = { x: number; y: number };
5
- export type LinearRegressionParamsType = { a: number; b: number };
6
- export type LinearRegressionPredictionType = number;
7
-
8
- export const LinearRegressionError = {
9
- MinPairs: "linear.regression.min.pairs",
10
- SumXTooBig: "linear.regression.sum.x.too.big",
11
- SumYTooBig: "linear.regression.sum.y.too.big",
12
- SumXSquaredTooBig: "linear.regression.sum.x.squared.too.big",
13
- SumXTimesYTooBig: "linear.regression.sum.x.times.y.too.big",
14
- ModelCreation: "linear.regression.model.creation",
15
- };
16
-
17
- export class LinearRegression {
18
- private static readonly DEFAULT_ROUNDING: RoundingStrategy = new RoundingToNearestStrategy();
19
-
20
- private readonly params: LinearRegressionParamsType;
21
- private readonly rounding: RoundingStrategy;
22
-
23
- constructor(params: LinearRegressionParamsType, rounding?: RoundingStrategy) {
24
- this.params = params;
25
- this.rounding = rounding ?? LinearRegression.DEFAULT_ROUNDING;
26
- }
27
-
28
- static fromPairs(pairs: LinearRegressionPairType[], rounding?: RoundingStrategy): LinearRegression {
29
- const count = pairs.length;
30
-
31
- if (count < 2) throw new Error(LinearRegressionError.MinPairs);
32
-
33
- let sumX = 0;
34
- let sumY = 0;
35
- let sumXX = 0;
36
- let sumXY = 0;
37
-
38
- for (let index = 0; index < count; index++) {
39
- const pair = pairs[index];
40
- sumX += pair.x;
41
- sumY += pair.y;
42
- sumXX += pair.x * pair.x;
43
- sumXY += pair.x * pair.y;
44
- }
45
-
46
- if (Math.abs(sumX) >= Number.MAX_SAFE_INTEGER) throw new Error(LinearRegressionError.SumXTooBig);
47
- if (Math.abs(sumY) >= Number.MAX_SAFE_INTEGER) throw new Error(LinearRegressionError.SumYTooBig);
48
- // Stryker disable all
49
- if (Math.abs(sumXY) >= Number.MAX_SAFE_INTEGER) throw new Error(LinearRegressionError.SumXTimesYTooBig);
50
- if (Math.abs(sumXX) >= Number.MAX_SAFE_INTEGER) throw new Error(LinearRegressionError.SumXSquaredTooBig);
51
- // Stryker restore all
52
-
53
- const bDenominator = sumXX - sumX ** 2 / count;
54
-
55
- if (bDenominator === 0) throw new Error(LinearRegressionError.ModelCreation);
56
-
57
- const b = (sumXY - (sumX * sumY) / count) / bDenominator;
58
- const a = (sumY - b * sumX) / count;
59
-
60
- return new LinearRegression({ a, b }, rounding);
61
- }
62
-
63
- predict(x: LinearRegressionPairType["x"], rounding?: RoundingStrategy): LinearRegressionPredictionType {
64
- const chosen = rounding ?? this.rounding;
65
- const prediction = this.params.b * x + this.params.a;
66
-
67
- return chosen.round(prediction);
68
- }
69
-
70
- inspect(): LinearRegression["params"] {
71
- return this.params;
72
- }
73
- }
@@ -1,18 +0,0 @@
1
- import type { RoundingStrategy } from "./rounding.strategy";
2
- import { RoundingDecimalStrategy } from "./rounding-decimal.strategy";
3
- import { Sum } from "./sum.service";
4
-
5
- export const MeanError = { NotEnoughValues: "mean.not.enough.values" };
6
-
7
- export class Mean {
8
- private static readonly DEFAULT_ROUNDING: RoundingStrategy = new RoundingDecimalStrategy(2);
9
-
10
- static calculate(values: number[], rounding?: RoundingStrategy): number {
11
- if (values.length === 0) throw new Error(MeanError.NotEnoughValues);
12
-
13
- const sum = Sum.of(values);
14
- const mean = sum / values.length;
15
-
16
- return (rounding ?? Mean.DEFAULT_ROUNDING).round(mean);
17
- }
18
- }
@@ -1,7 +0,0 @@
1
- export const MIME_TYPES = {
2
- wildcard: ["*/*"],
3
- jpeg: ["image/jpeg"],
4
- png: ["image/png"],
5
- wav: ["audio/x-wav", "audio/wav"],
6
- mp4: ["video/mp4"],
7
- } as const;
@@ -1,14 +0,0 @@
1
- import { z } from "zod/v4";
2
-
3
- export const MimeValueError = { Type: "mime.value.type", Invalid: "mime.value.invalid" };
4
-
5
- // One to twenty four lowercase letters, asterisk or hyphen, forward slash, one to twenty four lowercase letters, asterisk or hyphen
6
- const MIME_VALUE_CHARS_WHITELIST = /^[a-z*-]{1,24}\/[a-z*-]{1,24}$/;
7
-
8
- // Stryker disable all
9
- export const MimeValue = z
10
- // Stryker restore all
11
- .string(MimeValueError.Type)
12
- .regex(MIME_VALUE_CHARS_WHITELIST, MimeValueError.Invalid)
13
- .transform((value) => ({ type: value.split("/")[0], subtype: value.split("/")[1] }))
14
- .brand("MimeValue");