@bgord/tools 1.4.5 → 1.4.7

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 (222) hide show
  1. package/package.json +3 -3
  2. package/dist/age-years.vo.d.ts +0 -11
  3. package/dist/age-years.vo.js +0 -6
  4. package/dist/age.vo.d.ts +0 -28
  5. package/dist/age.vo.js +0 -51
  6. package/dist/api-key.vo.d.ts +0 -7
  7. package/dist/api-key.vo.js +0 -7
  8. package/dist/basename.vo.d.ts +0 -12
  9. package/dist/basename.vo.js +0 -22
  10. package/dist/batch.d.ts +0 -2
  11. package/dist/batch.js +0 -3
  12. package/dist/date-calculator.service.d.ts +0 -10
  13. package/dist/date-calculator.service.js +0 -12
  14. package/dist/date-formatter.service.d.ts +0 -9
  15. package/dist/date-formatter.service.js +0 -15
  16. package/dist/date-range.vo.d.ts +0 -21
  17. package/dist/date-range.vo.js +0 -35
  18. package/dist/day-iso-id.vo.d.ts +0 -9
  19. package/dist/day-iso-id.vo.js +0 -12
  20. package/dist/day.vo.d.ts +0 -16
  21. package/dist/day.vo.js +0 -43
  22. package/dist/directory-path-absolute.vo.d.ts +0 -12
  23. package/dist/directory-path-absolute.vo.js +0 -20
  24. package/dist/directory-path-relative.vo.d.ts +0 -12
  25. package/dist/directory-path-relative.vo.js +0 -17
  26. package/dist/distance-value.vo.d.ts +0 -7
  27. package/dist/distance-value.vo.js +0 -5
  28. package/dist/distance.vo.d.ts +0 -23
  29. package/dist/distance.vo.js +0 -53
  30. package/dist/division-factor.vo.d.ts +0 -7
  31. package/dist/division-factor.vo.js +0 -5
  32. package/dist/dll.service.d.ts +0 -29
  33. package/dist/dll.service.js +0 -148
  34. package/dist/duration-ms.vo.d.ts +0 -6
  35. package/dist/duration-ms.vo.js +0 -5
  36. package/dist/duration.service.d.ts +0 -37
  37. package/dist/duration.service.js +0 -87
  38. package/dist/email-mask.service.d.ts +0 -4
  39. package/dist/email-mask.service.js +0 -12
  40. package/dist/email.vo.d.ts +0 -6
  41. package/dist/email.vo.js +0 -4
  42. package/dist/etags.vo.d.ts +0 -23
  43. package/dist/etags.vo.js +0 -37
  44. package/dist/extension.vo.d.ts +0 -9
  45. package/dist/extension.vo.js +0 -15
  46. package/dist/feature-flag-value.vo.d.ts +0 -10
  47. package/dist/feature-flag-value.vo.js +0 -8
  48. package/dist/feature-flag.vo.d.ts +0 -5
  49. package/dist/feature-flag.vo.js +0 -9
  50. package/dist/file-path-absolute-schema.vo.d.ts +0 -17
  51. package/dist/file-path-absolute-schema.vo.js +0 -20
  52. package/dist/file-path-relative-schema.vo.d.ts +0 -17
  53. package/dist/file-path-relative-schema.vo.js +0 -20
  54. package/dist/file-path.vo.d.ts +0 -31
  55. package/dist/file-path.vo.js +0 -81
  56. package/dist/filename-affix.vo.d.ts +0 -13
  57. package/dist/filename-affix.vo.js +0 -17
  58. package/dist/filename-from-string.vo.d.ts +0 -10
  59. package/dist/filename-from-string.vo.js +0 -17
  60. package/dist/filename.vo.d.ts +0 -24
  61. package/dist/filename.vo.js +0 -69
  62. package/dist/height-milimiters.vo.d.ts +0 -7
  63. package/dist/height-milimiters.vo.js +0 -8
  64. package/dist/height.vo.d.ts +0 -21
  65. package/dist/height.vo.js +0 -51
  66. package/dist/hour-value.vo.d.ts +0 -7
  67. package/dist/hour-value.vo.js +0 -5
  68. package/dist/hour.vo.d.ts +0 -20
  69. package/dist/hour.vo.js +0 -48
  70. package/dist/iban-mask.service.d.ts +0 -4
  71. package/dist/iban-mask.service.js +0 -12
  72. package/dist/iban-schema.vo.d.ts +0 -7
  73. package/dist/iban-schema.vo.js +0 -7
  74. package/dist/iban.vo.d.ts +0 -9
  75. package/dist/iban.vo.js +0 -23
  76. package/dist/image.vo.d.ts +0 -13
  77. package/dist/image.vo.js +0 -10
  78. package/dist/index.d.ts +0 -110
  79. package/dist/index.js +0 -110
  80. package/dist/int.vo.d.ts +0 -8
  81. package/dist/int.vo.js +0 -15
  82. package/dist/integer-non-negative.vo.d.ts +0 -7
  83. package/dist/integer-non-negative.vo.js +0 -8
  84. package/dist/integer-positive.vo.d.ts +0 -7
  85. package/dist/integer-positive.vo.js +0 -5
  86. package/dist/integer.vo.d.ts +0 -6
  87. package/dist/integer.vo.js +0 -4
  88. package/dist/language.vo.d.ts +0 -7
  89. package/dist/language.vo.js +0 -5
  90. package/dist/linear-regression.service.d.ts +0 -27
  91. package/dist/linear-regression.service.js +0 -58
  92. package/dist/mean.service.d.ts +0 -8
  93. package/dist/mean.service.js +0 -13
  94. package/dist/mime-registry-entry.vo.d.ts +0 -7
  95. package/dist/mime-registry-entry.vo.js +0 -8
  96. package/dist/mime-registry.service.d.ts +0 -16
  97. package/dist/mime-registry.service.js +0 -31
  98. package/dist/mime-value.vo.d.ts +0 -7
  99. package/dist/mime-value.vo.js +0 -7
  100. package/dist/mime.vo.d.ts +0 -12
  101. package/dist/mime.vo.js +0 -26
  102. package/dist/mimes.d.ts +0 -13
  103. package/dist/mimes.js +0 -19
  104. package/dist/min-max-scaler.service.d.ts +0 -46
  105. package/dist/min-max-scaler.service.js +0 -61
  106. package/dist/minute-value.vo.d.ts +0 -7
  107. package/dist/minute-value.vo.js +0 -5
  108. package/dist/minute.vo.d.ts +0 -20
  109. package/dist/minute.vo.js +0 -48
  110. package/dist/money-amount.vo.d.ts +0 -7
  111. package/dist/money-amount.vo.js +0 -5
  112. package/dist/money.vo.d.ts +0 -26
  113. package/dist/money.vo.js +0 -56
  114. package/dist/month-iso-id.vo.d.ts +0 -8
  115. package/dist/month-iso-id.vo.js +0 -14
  116. package/dist/month.vo.d.ts +0 -16
  117. package/dist/month.vo.js +0 -40
  118. package/dist/multiplication-factor.vo.d.ts +0 -7
  119. package/dist/multiplication-factor.vo.js +0 -8
  120. package/dist/noop.service.d.ts +0 -2
  121. package/dist/noop.service.js +0 -2
  122. package/dist/object-key.vo.d.ts +0 -11
  123. package/dist/object-key.vo.js +0 -19
  124. package/dist/outlier-detector.service.d.ts +0 -9
  125. package/dist/outlier-detector.service.js +0 -16
  126. package/dist/package-version-schema.vo.d.ts +0 -8
  127. package/dist/package-version-schema.vo.js +0 -10
  128. package/dist/package-version.vo.d.ts +0 -22
  129. package/dist/package-version.vo.js +0 -58
  130. package/dist/pagination-page.vo.d.ts +0 -6
  131. package/dist/pagination-page.vo.js +0 -3
  132. package/dist/pagination-skip.vo.d.ts +0 -7
  133. package/dist/pagination-skip.vo.js +0 -3
  134. package/dist/pagination-take.vo.d.ts +0 -7
  135. package/dist/pagination-take.vo.js +0 -3
  136. package/dist/pagination.service.d.ts +0 -53
  137. package/dist/pagination.service.js +0 -44
  138. package/dist/percentage.service.d.ts +0 -7
  139. package/dist/percentage.service.js +0 -9
  140. package/dist/population-standard-deviation.service.d.ts +0 -7
  141. package/dist/population-standard-deviation.service.js +0 -17
  142. package/dist/quarter-iso-id.vo.d.ts +0 -8
  143. package/dist/quarter-iso-id.vo.js +0 -7
  144. package/dist/quarter.vo.d.ts +0 -12
  145. package/dist/quarter.vo.js +0 -30
  146. package/dist/random.service.d.ts +0 -13
  147. package/dist/random.service.js +0 -13
  148. package/dist/rate-limiter.service.d.ts +0 -17
  149. package/dist/rate-limiter.service.js +0 -19
  150. package/dist/relative-date.vo.d.ts +0 -13
  151. package/dist/relative-date.vo.js +0 -14
  152. package/dist/reordering-item-position-value.vo.d.ts +0 -6
  153. package/dist/reordering-item-position-value.vo.js +0 -3
  154. package/dist/reordering.service.d.ts +0 -63
  155. package/dist/reordering.service.js +0 -135
  156. package/dist/repeat.d.ts +0 -1
  157. package/dist/repeat.js +0 -3
  158. package/dist/revision-value.vo.d.ts +0 -7
  159. package/dist/revision-value.vo.js +0 -3
  160. package/dist/revision.vo.d.ts +0 -18
  161. package/dist/revision.vo.js +0 -36
  162. package/dist/rounding-decimal.strategy.d.ts +0 -12
  163. package/dist/rounding-decimal.strategy.js +0 -14
  164. package/dist/rounding-down.strategy.d.ts +0 -4
  165. package/dist/rounding-down.strategy.js +0 -5
  166. package/dist/rounding-to-nearest.strategy.d.ts +0 -4
  167. package/dist/rounding-to-nearest.strategy.js +0 -5
  168. package/dist/rounding-up.strategy.d.ts +0 -4
  169. package/dist/rounding-up.strategy.js +0 -5
  170. package/dist/rounding.strategy.d.ts +0 -3
  171. package/dist/rounding.strategy.js +0 -1
  172. package/dist/size-bytes.vo.d.ts +0 -6
  173. package/dist/size-bytes.vo.js +0 -5
  174. package/dist/size.vo.d.ts +0 -41
  175. package/dist/size.vo.js +0 -91
  176. package/dist/slug.service.d.ts +0 -4
  177. package/dist/slug.service.js +0 -15
  178. package/dist/sms-body.vo.d.ts +0 -8
  179. package/dist/sms-body.vo.js +0 -9
  180. package/dist/sms-message.vo.d.ts +0 -13
  181. package/dist/sms-message.vo.js +0 -13
  182. package/dist/sum.service.d.ts +0 -4
  183. package/dist/sum.service.js +0 -16
  184. package/dist/telephone-number.vo.d.ts +0 -7
  185. package/dist/telephone-number.vo.js +0 -10
  186. package/dist/thousands-separator.service.d.ts +0 -4
  187. package/dist/thousands-separator.service.js +0 -9
  188. package/dist/time-zone-offset-value.vo.d.ts +0 -8
  189. package/dist/time-zone-offset-value.vo.js +0 -13
  190. package/dist/timestamp-value.vo.d.ts +0 -6
  191. package/dist/timestamp-value.vo.js +0 -5
  192. package/dist/timestamp.vo.d.ts +0 -21
  193. package/dist/timestamp.vo.js +0 -54
  194. package/dist/timezone.vo.d.ts +0 -9
  195. package/dist/timezone.vo.js +0 -20
  196. package/dist/ts-utils.d.ts +0 -3
  197. package/dist/ts-utils.js +0 -1
  198. package/dist/tsconfig.tsbuildinfo +0 -1
  199. package/dist/url-with-slash.vo.d.ts +0 -6
  200. package/dist/url-with-slash.vo.js +0 -5
  201. package/dist/url-without-slash.vo.d.ts +0 -6
  202. package/dist/url-without-slash.vo.js +0 -5
  203. package/dist/visually-unambiguous-characters-generator.service.d.ts +0 -4
  204. package/dist/visually-unambiguous-characters-generator.service.js +0 -32
  205. package/dist/week-iso-id.vo.d.ts +0 -8
  206. package/dist/week-iso-id.vo.js +0 -19
  207. package/dist/week.vo.d.ts +0 -16
  208. package/dist/week.vo.js +0 -45
  209. package/dist/weekday-iso-id.vo.d.ts +0 -7
  210. package/dist/weekday-iso-id.vo.js +0 -5
  211. package/dist/weekday.vo.d.ts +0 -28
  212. package/dist/weekday.vo.js +0 -60
  213. package/dist/weight-grams.vo.d.ts +0 -7
  214. package/dist/weight-grams.vo.js +0 -5
  215. package/dist/weight.vo.d.ts +0 -25
  216. package/dist/weight.vo.js +0 -65
  217. package/dist/year-iso-id.vo.d.ts +0 -7
  218. package/dist/year-iso-id.vo.js +0 -7
  219. package/dist/year.vo.d.ts +0 -18
  220. package/dist/year.vo.js +0 -50
  221. package/dist/z-score.service.d.ts +0 -11
  222. package/dist/z-score.service.js +0 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/tools",
3
- "version": "1.4.5",
3
+ "version": "1.4.7",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Bartosz Gordon",
@@ -26,12 +26,12 @@
26
26
  "@stryker-mutator/core": "9.6.0",
27
27
  "@types/bun": "1.3.11",
28
28
  "cspell": "9.7.0",
29
- "knip": "6.0.2",
29
+ "knip": "6.0.4",
30
30
  "lefthook": "2.1.4",
31
31
  "lockfile-lint": "5.0.0",
32
32
  "only-allow": "1.2.2",
33
33
  "shellcheck": "4.1.0",
34
- "typescript": "5.9.3"
34
+ "typescript": "6.0.2"
35
35
  },
36
36
  "dependencies": {
37
37
  "date-fns": "4.1.0",
@@ -1,11 +0,0 @@
1
- import * as v from "valibot";
2
- export declare const AgeYearsError: {
3
- Type: string;
4
- Invalid: string;
5
- };
6
- export declare const AgeYearsConstraints: {
7
- min: number;
8
- max: number;
9
- };
10
- export declare const AgeYears: v.SchemaWithPipe<readonly [v.NumberSchema<string>, v.IntegerAction<number, string>, v.MinValueAction<number, 0, string>, v.MaxValueAction<number, 130, string>, v.BrandAction<number, "AgeYears">]>;
11
- export type AgeYearsType = v.InferOutput<typeof AgeYears>;
@@ -1,6 +0,0 @@
1
- import * as v from "valibot";
2
- export const AgeYearsError = { Type: "age.years.type", Invalid: "age.years.invalid" };
3
- export const AgeYearsConstraints = { min: 0, max: 130 };
4
- export const AgeYears = v.pipe(v.number(AgeYearsError.Type), v.integer(AgeYearsError.Type), v.minValue(0, AgeYearsError.Invalid), v.maxValue(130, AgeYearsError.Invalid),
5
- // Stryker disable next-line StringLiteral
6
- v.brand("AgeYears"));
package/dist/age.vo.d.ts DELETED
@@ -1,28 +0,0 @@
1
- import { type AgeYearsType } from "./age-years.vo";
2
- import { Timestamp } from "./timestamp.vo";
3
- export declare const AgeError: {
4
- FutureBirthdate: string;
5
- };
6
- export declare class Age {
7
- private readonly value;
8
- static readonly MIN: number;
9
- static readonly MAX: number;
10
- private constructor();
11
- static fromValue(candidate: number): Age;
12
- static fromValueSafe(candidate: AgeYearsType): Age;
13
- static fromBirthdateTimestamp(params: {
14
- birthdate: Timestamp;
15
- now: Timestamp;
16
- }): Age;
17
- static fromBirthdate(candidate: {
18
- birthdate: string;
19
- now: Timestamp;
20
- }): Age;
21
- get(): AgeYearsType;
22
- equals(other: Age): boolean;
23
- isOlderThan(other: Age): boolean;
24
- isYoungerThan(other: Age): boolean;
25
- isAdult(minimumAge: Age): boolean;
26
- toString(): string;
27
- toJSON(): number;
28
- }
package/dist/age.vo.js DELETED
@@ -1,51 +0,0 @@
1
- import { differenceInYears } from "date-fns";
2
- import * as v from "valibot";
3
- import { AgeYears, AgeYearsConstraints } from "./age-years.vo";
4
- import { Timestamp } from "./timestamp.vo";
5
- export const AgeError = { FutureBirthdate: "age.future.birthdate" };
6
- export class Age {
7
- value;
8
- static MIN = AgeYearsConstraints.min;
9
- static MAX = AgeYearsConstraints.max;
10
- constructor(value) {
11
- this.value = value;
12
- }
13
- static fromValue(candidate) {
14
- return new Age(v.parse(AgeYears, candidate));
15
- }
16
- static fromValueSafe(candidate) {
17
- return new Age(candidate);
18
- }
19
- static fromBirthdateTimestamp(params) {
20
- if (params.birthdate.isAfter(params.now))
21
- throw new Error(AgeError.FutureBirthdate);
22
- return Age.fromValue(differenceInYears(params.now.ms, params.birthdate.ms));
23
- }
24
- static fromBirthdate(candidate) {
25
- const birthdate = Timestamp.fromDateLike(candidate.birthdate);
26
- if (birthdate.isAfter(candidate.now))
27
- throw new Error(AgeError.FutureBirthdate);
28
- return Age.fromValue(differenceInYears(candidate.now.ms, birthdate.ms));
29
- }
30
- get() {
31
- return this.value;
32
- }
33
- equals(other) {
34
- return this.value === other.value;
35
- }
36
- isOlderThan(other) {
37
- return this.value > other.value;
38
- }
39
- isYoungerThan(other) {
40
- return this.value < other.value;
41
- }
42
- isAdult(minimumAge) {
43
- return this.value >= minimumAge.value;
44
- }
45
- toString() {
46
- return this.get().toString();
47
- }
48
- toJSON() {
49
- return this.get();
50
- }
51
- }
@@ -1,7 +0,0 @@
1
- import * as v from "valibot";
2
- export declare const ApiKeyError: {
3
- Type: string;
4
- BadChars: string;
5
- };
6
- export declare const ApiKey: v.SchemaWithPipe<readonly [v.StringSchema<string>, v.RegexAction<string, string>, v.BrandAction<string, "ApiKey">]>;
7
- export type ApiKeyType = v.InferOutput<typeof ApiKey>;
@@ -1,7 +0,0 @@
1
- import * as v from "valibot";
2
- export const ApiKeyError = { Type: "api.key.type", BadChars: "api.key.bad.chars" };
3
- // 64 letters and digits allowed
4
- const API_KEY_CHARS = /^[a-zA-Z0-9]{64}$/;
5
- export const ApiKey = v.pipe(v.string(ApiKeyError.Type), v.regex(API_KEY_CHARS, ApiKeyError.BadChars),
6
- // Stryker disable next-line StringLiteral
7
- v.brand("ApiKey"));
@@ -1,12 +0,0 @@
1
- import * as v from "valibot";
2
- export declare const BasenameError: {
3
- Type: string;
4
- Empty: string;
5
- TooLong: string;
6
- DotSegments: string;
7
- Dotfiles: string;
8
- TrailingDot: string;
9
- BadChars: string;
10
- };
11
- export declare const Basename: v.SchemaWithPipe<readonly [v.StringSchema<string>, v.MinLengthAction<string, 1, string>, v.MaxLengthAction<string, 128, string>, v.CheckAction<string, string>, v.CheckAction<string, string>, v.CheckAction<string, string>, v.RegexAction<string, string>, v.BrandAction<string, "Basename">]>;
12
- export type BasenameType = v.InferOutput<typeof Basename>;
@@ -1,22 +0,0 @@
1
- import * as v from "valibot";
2
- export const BasenameError = {
3
- Type: "basename.type",
4
- Empty: "basename.empty",
5
- TooLong: "basename.too.long",
6
- DotSegments: "basename.dot.segments",
7
- Dotfiles: "basename.dotfiles",
8
- TrailingDot: "basename.trailing.dot",
9
- BadChars: "basename.bad.chars",
10
- };
11
- // Letters, digits, dots, underscores, and hyphens allowed
12
- const BASENAME_CHARS = /^[a-zA-Z0-9._-]+$/;
13
- const DOT_SEGMENTS = [".", ".."];
14
- export const Basename = v.pipe(v.string(BasenameError.Type), v.minLength(1, BasenameError.Empty), v.maxLength(128, BasenameError.TooLong),
15
- // Reject "." and ".." as a filename to avoid directory traversal
16
- v.check((value) => !DOT_SEGMENTS.includes(value), BasenameError.DotSegments),
17
- // Reject dotfiles like ".env"
18
- v.check((value) => !value.startsWith("."), BasenameError.Dotfiles),
19
- // Reject trailing dot like "picture." to avoid extension collision
20
- v.check((value) => !value.endsWith("."), BasenameError.TrailingDot), v.regex(BASENAME_CHARS, BasenameError.BadChars),
21
- // Stryker disable next-line StringLiteral
22
- v.brand("Basename"));
package/dist/batch.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { IntegerPositiveType } from "./integer-positive.vo";
2
- export declare function batch<T>(array: Array<T>, size: IntegerPositiveType): Array<Array<T>>;
package/dist/batch.js DELETED
@@ -1,3 +0,0 @@
1
- export function batch(array, size) {
2
- return Array.from({ length: Math.ceil(array.length / size) }, (_, index) => array.slice(index * size, (index + 1) * size));
3
- }
@@ -1,10 +0,0 @@
1
- import { Duration } from "./duration.service";
2
- import { Timestamp } from "./timestamp.vo";
3
- type GetStartOfDayTsInTzConfigType = {
4
- now: Timestamp;
5
- timeZoneOffset: Duration;
6
- };
7
- export declare class DateCalculator {
8
- static getStartOfDayTsInTz(config: GetStartOfDayTsInTzConfigType): Timestamp;
9
- }
10
- export {};
@@ -1,12 +0,0 @@
1
- import { Duration } from "./duration.service";
2
- import { Timestamp } from "./timestamp.vo";
3
- export class DateCalculator {
4
- static getStartOfDayTsInTz(config) {
5
- const dayMs = Duration.Days(1).ms;
6
- const utcMidnightOfNow = Timestamp.fromNumber(Math.floor(config.now.ms / dayMs) * dayMs);
7
- let startOfDayInTz = utcMidnightOfNow.add(config.timeZoneOffset);
8
- if (startOfDayInTz.isAfter(config.now))
9
- startOfDayInTz = startOfDayInTz.subtract(Duration.Days(1));
10
- return startOfDayInTz;
11
- }
12
- }
@@ -1,9 +0,0 @@
1
- import { format } from "date-fns";
2
- type DateFormattersInputType = Parameters<typeof format>[0];
3
- export declare class DateFormatters {
4
- static datetime(date: DateFormattersInputType): string;
5
- static date(date: DateFormattersInputType): string;
6
- static monthDay(date: DateFormattersInputType): string;
7
- static relative(date: DateFormattersInputType): string;
8
- }
9
- export {};
@@ -1,15 +0,0 @@
1
- import { format, formatDistanceToNow } from "date-fns";
2
- export class DateFormatters {
3
- static datetime(date) {
4
- return format(date, "yyyy/MM/dd HH:mm");
5
- }
6
- static date(date) {
7
- return format(date, "yyyy/MM/dd");
8
- }
9
- static monthDay(date) {
10
- return format(date, "MM/dd");
11
- }
12
- static relative(date) {
13
- return formatDistanceToNow(date, { addSuffix: true });
14
- }
15
- }
@@ -1,21 +0,0 @@
1
- import type { Duration } from "./duration.service";
2
- import type { Timestamp } from "./timestamp.vo";
3
- export declare const DateRangeError: {
4
- Invalid: string;
5
- };
6
- export declare class DateRange {
7
- private readonly start;
8
- private readonly end;
9
- constructor(start: Timestamp, end: Timestamp);
10
- getStart(): Timestamp;
11
- getEnd(): Timestamp;
12
- get(): [Timestamp, Timestamp];
13
- getDuration(): Duration;
14
- contains(timestamp: Timestamp): boolean;
15
- equals(other: DateRange): boolean;
16
- toString(): string;
17
- toJSON(): {
18
- start: number;
19
- end: number;
20
- };
21
- }
@@ -1,35 +0,0 @@
1
- export const DateRangeError = { Invalid: "date.range.invalid" };
2
- export class DateRange {
3
- start;
4
- end;
5
- constructor(start, end) {
6
- this.start = start;
7
- this.end = end;
8
- if (start.isAfterOrEqual(end))
9
- throw new Error(DateRangeError.Invalid);
10
- }
11
- getStart() {
12
- return this.start;
13
- }
14
- getEnd() {
15
- return this.end;
16
- }
17
- get() {
18
- return [this.start, this.end];
19
- }
20
- getDuration() {
21
- return this.end.difference(this.start);
22
- }
23
- contains(timestamp) {
24
- return timestamp.isAfterOrEqual(this.start) && timestamp.isBeforeOrEqual(this.end);
25
- }
26
- equals(other) {
27
- return this.start.equals(other.start) && this.end.equals(other.end);
28
- }
29
- toString() {
30
- return `${this.start.toString()} - ${this.end.toString()}`;
31
- }
32
- toJSON() {
33
- return { start: this.getStart().ms, end: this.getEnd().ms };
34
- }
35
- }
@@ -1,9 +0,0 @@
1
- import * as v from "valibot";
2
- export declare const DayIsoIdError: {
3
- Type: string;
4
- BadChars: string;
5
- InvalidDate: string;
6
- };
7
- export declare const DAY_ISO_ID_CHARS: RegExp;
8
- export declare const DayIsoId: v.SchemaWithPipe<readonly [v.StringSchema<string>, v.RegexAction<string, string>, v.CheckAction<string, string>, v.BrandAction<string, "DayIsoId">]>;
9
- export type DayIsoIdType = v.InferOutput<typeof DayIsoId>;
@@ -1,12 +0,0 @@
1
- import { isValid, parseISO } from "date-fns";
2
- import * as v from "valibot";
3
- export const DayIsoIdError = {
4
- Type: "day.iso.id.type",
5
- BadChars: "day.iso.id.bad.chars",
6
- InvalidDate: "day.iso.id.invalid.date",
7
- };
8
- // Four digits, hyphen, two digits, hyphen, two digits
9
- export const DAY_ISO_ID_CHARS = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/;
10
- export const DayIsoId = v.pipe(v.string(DayIsoIdError.Type), v.regex(DAY_ISO_ID_CHARS, DayIsoIdError.BadChars), v.check((value) => isValid(parseISO(value)), DayIsoIdError.InvalidDate),
11
- // Stryker disable next-line StringLiteral
12
- v.brand("DayIsoId"));
package/dist/day.vo.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { DateRange } from "./date-range.vo";
2
- import { type DayIsoIdType } from "./day-iso-id.vo";
3
- import type { IntegerType } from "./integer.vo";
4
- import { Timestamp } from "./timestamp.vo";
5
- import type { TimestampValueType } from "./timestamp-value.vo";
6
- export declare class Day extends DateRange {
7
- static fromTimestamp(timestamp: Timestamp): Day;
8
- static fromTimestampValue(timestamp: TimestampValueType): Day;
9
- static fromNow(now: Timestamp): Day;
10
- static fromIsoId(isoId: DayIsoIdType): Day;
11
- toIsoId(): DayIsoIdType;
12
- previous(): Day;
13
- next(): Day;
14
- shift(count: IntegerType): Day;
15
- toString(): string;
16
- }
package/dist/day.vo.js DELETED
@@ -1,43 +0,0 @@
1
- import { formatISO } from "date-fns";
2
- import * as v from "valibot";
3
- import { DateRange } from "./date-range.vo";
4
- import { DayIsoId } from "./day-iso-id.vo";
5
- import { Duration } from "./duration.service";
6
- import { Int } from "./int.vo";
7
- import { Timestamp } from "./timestamp.vo";
8
- export class Day extends DateRange {
9
- static fromTimestamp(timestamp) {
10
- const date = new Date(timestamp.ms);
11
- const startUtc = Timestamp.fromNumber(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()));
12
- const endUtc = startUtc.add(Duration.Days(1)).subtract(Duration.Ms(1));
13
- return new Day(startUtc, endUtc);
14
- }
15
- static fromTimestampValue(timestamp) {
16
- return Day.fromTimestamp(Timestamp.fromValue(timestamp));
17
- }
18
- static fromNow(now) {
19
- return Day.fromTimestamp(now);
20
- }
21
- static fromIsoId(isoId) {
22
- const [year, month, day] = v.parse(DayIsoId, isoId).split("-").map(Number);
23
- const startUtc = Timestamp.fromNumber(Date.UTC(year, month - 1, day));
24
- const endUtc = startUtc.add(Duration.Days(1)).subtract(Duration.Ms(1));
25
- return new Day(startUtc, endUtc);
26
- }
27
- toIsoId() {
28
- const midday = this.getStart().add(Duration.Hours(12));
29
- return v.parse(DayIsoId, formatISO(midday.ms, { representation: "date" }));
30
- }
31
- previous() {
32
- return this.shift(Int.of(-1));
33
- }
34
- next() {
35
- return this.shift(Int.of(1));
36
- }
37
- shift(count) {
38
- return Day.fromTimestamp(this.getStart().add(Duration.Days(count)));
39
- }
40
- toString() {
41
- return this.toIsoId();
42
- }
43
- }
@@ -1,12 +0,0 @@
1
- import * as v from "valibot";
2
- export declare const DirectoryPathAbsoluteError: {
3
- BadSegments: string;
4
- Empty: string;
5
- LeadingSlash: string;
6
- TooLong: string;
7
- TrailingSlash: string;
8
- Type: string;
9
- };
10
- export declare const DIRECTORY_PATH_ABSOLUTE_CHARS: RegExp;
11
- export declare const DirectoryPathAbsoluteSchema: v.SchemaWithPipe<readonly [v.StringSchema<string>, v.MinLengthAction<string, 1, string>, v.MaxLengthAction<string, 512, string>, v.CheckAction<string, string>, v.CheckAction<string, string>, v.CheckAction<string, string>, v.BrandAction<string, "DirectoryPathAbsoluteSchema">]>;
12
- export type DirectoryPathAbsoluteType = v.InferOutput<typeof DirectoryPathAbsoluteSchema>;
@@ -1,20 +0,0 @@
1
- import * as v from "valibot";
2
- export const DirectoryPathAbsoluteError = {
3
- BadSegments: "directory.path.absolue.bad.segments",
4
- Empty: "directory.path.absolue.empty",
5
- LeadingSlash: "directory.path.absolue.leading.slash",
6
- TooLong: "directory.path.absolue.too.long",
7
- TrailingSlash: "directory.path.absolue.trailing.slash",
8
- Type: "directory.path.absolue.type",
9
- };
10
- // Letters, digits, dots, underscores, and hyphens
11
- export const DIRECTORY_PATH_ABSOLUTE_CHARS = /^[a-zA-Z0-9._-]+$/;
12
- const DOT_SEGMENTS = [".", ".."];
13
- export const DirectoryPathAbsoluteSchema = v.pipe(v.string(DirectoryPathAbsoluteError.Type), v.minLength(1, DirectoryPathAbsoluteError.Empty), v.maxLength(512, DirectoryPathAbsoluteError.TooLong), v.check((value) => value.startsWith("/"), DirectoryPathAbsoluteError.LeadingSlash), v.check((value) => (value === "/" ? true : !value.endsWith("/")), DirectoryPathAbsoluteError.TrailingSlash), v.check((value) => {
14
- if (value === "/")
15
- return true;
16
- const segments = value.slice(1).split("/");
17
- return segments.every((segment) => DIRECTORY_PATH_ABSOLUTE_CHARS.test(segment) && !DOT_SEGMENTS.includes(segment));
18
- }, DirectoryPathAbsoluteError.BadSegments),
19
- // Stryker disable next-line StringLiteral
20
- v.brand("DirectoryPathAbsoluteSchema"));
@@ -1,12 +0,0 @@
1
- import * as v from "valibot";
2
- export declare const DirectoryPathRelativeError: {
3
- BadSegments: string;
4
- Empty: string;
5
- LeadingSlash: string;
6
- TooLong: string;
7
- TrailingSlash: string;
8
- Type: string;
9
- };
10
- export declare const DIRECTORY_PATH_RELATIVE_CHARS: RegExp;
11
- export declare const DirectoryPathRelativeSchema: v.SchemaWithPipe<readonly [v.StringSchema<string>, v.MinLengthAction<string, 1, string>, v.MaxLengthAction<string, 512, string>, v.CheckAction<string, string>, v.CheckAction<string, string>, v.CheckAction<string, string>, v.BrandAction<string, "DirectoryPathRelativeSchema">]>;
12
- export type DirectoryPathRelativeType = v.InferOutput<typeof DirectoryPathRelativeSchema>;
@@ -1,17 +0,0 @@
1
- import * as v from "valibot";
2
- export const DirectoryPathRelativeError = {
3
- BadSegments: "directory.path.relative.bad.segments",
4
- Empty: "directory.path.relative.empty",
5
- LeadingSlash: "directory.path.relative.leading.slash",
6
- TooLong: "directory.path.absolue.too.long",
7
- TrailingSlash: "directory.path.absolue.trailing.slash",
8
- Type: "directory.path.relative.type",
9
- };
10
- // Letters, digits, dots, underscores, and hyphens
11
- export const DIRECTORY_PATH_RELATIVE_CHARS = /^[A-Za-z0-9._-]+$/;
12
- const DOT_SEGMENTS = [".", ".."];
13
- export const DirectoryPathRelativeSchema = v.pipe(v.string(DirectoryPathRelativeError.Type), v.minLength(1, DirectoryPathRelativeError.Empty), v.maxLength(512, DirectoryPathRelativeError.TooLong), v.check((value) => !value.startsWith("/"), DirectoryPathRelativeError.LeadingSlash), v.check((value) => !value.endsWith("/"), DirectoryPathRelativeError.TrailingSlash), v.check((value) => value
14
- .split("/")
15
- .every((segment) => DIRECTORY_PATH_RELATIVE_CHARS.test(segment) && !DOT_SEGMENTS.includes(segment)), DirectoryPathRelativeError.BadSegments),
16
- // Stryker disable next-line StringLiteral
17
- v.brand("DirectoryPathRelativeSchema"));
@@ -1,7 +0,0 @@
1
- import * as v from "valibot";
2
- export declare const DistanceValueError: {
3
- Type: string;
4
- Invalid: string;
5
- };
6
- export declare const DistanceValue: v.SchemaWithPipe<readonly [v.NumberSchema<string>, v.IntegerAction<number, string>, v.MinValueAction<number, 0, string>, v.BrandAction<number, "DistanceValue">]>;
7
- export type DistanceValueType = v.InferOutput<typeof DistanceValue>;
@@ -1,5 +0,0 @@
1
- import * as v from "valibot";
2
- export const DistanceValueError = { Type: "distance.value.type", Invalid: "distance.value.invalid" };
3
- export const DistanceValue = v.pipe(v.number(DistanceValueError.Type), v.integer(DistanceValueError.Type), v.minValue(0, DistanceValueError.Invalid),
4
- // Stryker disable next-line StringLiteral
5
- v.brand("DistanceValue"));
@@ -1,23 +0,0 @@
1
- import { type DistanceValueType } from "./distance-value.vo";
2
- import type { RoundingStrategy } from "./rounding.strategy";
3
- export declare const DistanceError: {
4
- SubtractResultLessThanZero: string;
5
- };
6
- export declare class Distance {
7
- private readonly value;
8
- private static readonly ZERO;
9
- private constructor();
10
- static fromMeters(candidate: number): Distance;
11
- static fromMetersSafe(candidate: DistanceValueType): Distance;
12
- static fromKilometers(candidate: number, rounding?: RoundingStrategy): Distance;
13
- static fromMiles(candidate: number, rounding?: RoundingStrategy): Distance;
14
- get(): DistanceValueType;
15
- add(distance: Distance): Distance;
16
- subtract(distance: Distance): Distance;
17
- equals(another: Distance): boolean;
18
- isLongerThan(another: Distance): boolean;
19
- isShorterThan(another: Distance): boolean;
20
- isZero(): boolean;
21
- toString(): string;
22
- toJSON(): number;
23
- }
@@ -1,53 +0,0 @@
1
- import * as v from "valibot";
2
- import { DistanceValue } from "./distance-value.vo";
3
- import { RoundingToNearestStrategy } from "./rounding-to-nearest.strategy";
4
- export const DistanceError = { SubtractResultLessThanZero: "distance.subtract.result.less.than.zero" };
5
- export class Distance {
6
- value;
7
- static ZERO = v.parse(DistanceValue, 0);
8
- constructor(value) {
9
- this.value = value;
10
- }
11
- static fromMeters(candidate) {
12
- return new Distance(v.parse(DistanceValue, candidate));
13
- }
14
- static fromMetersSafe(candidate) {
15
- return new Distance(candidate);
16
- }
17
- static fromKilometers(candidate, rounding = new RoundingToNearestStrategy()) {
18
- return new Distance(v.parse(DistanceValue, rounding.round(candidate * 1000)));
19
- }
20
- static fromMiles(candidate, rounding = new RoundingToNearestStrategy()) {
21
- return new Distance(v.parse(DistanceValue, rounding.round(candidate * 1_609.344)));
22
- }
23
- get() {
24
- return this.value;
25
- }
26
- add(distance) {
27
- return new Distance(v.parse(DistanceValue, this.value + distance.get()));
28
- }
29
- subtract(distance) {
30
- const result = this.value - distance.get();
31
- if (result < Distance.ZERO)
32
- throw new Error(DistanceError.SubtractResultLessThanZero);
33
- return new Distance(v.parse(DistanceValue, result));
34
- }
35
- equals(another) {
36
- return this.value === another.get();
37
- }
38
- isLongerThan(another) {
39
- return this.value > another.get();
40
- }
41
- isShorterThan(another) {
42
- return this.value < another.get();
43
- }
44
- isZero() {
45
- return this.value === Distance.ZERO;
46
- }
47
- toString() {
48
- return this.value.toString();
49
- }
50
- toJSON() {
51
- return this.value;
52
- }
53
- }
@@ -1,7 +0,0 @@
1
- import * as v from "valibot";
2
- export declare const DivisionFactorError: {
3
- Type: string;
4
- Invalid: string;
5
- };
6
- export declare const DivisionFactor: v.SchemaWithPipe<readonly [v.NumberSchema<string>, v.GtValueAction<number, 0, string>, v.BrandAction<number, "DivisionFactor">]>;
7
- export type DivisionFactorType = v.InferOutput<typeof DivisionFactor>;
@@ -1,5 +0,0 @@
1
- import * as v from "valibot";
2
- export const DivisionFactorError = { Type: "division.factor.type", Invalid: "division.factor.invalid" };
3
- export const DivisionFactor = v.pipe(v.number(DivisionFactorError.Type), v.gtValue(0, DivisionFactorError.Invalid),
4
- // Stryker disable next-line StringLiteral
5
- v.brand("DivisionFactor"));
@@ -1,29 +0,0 @@
1
- export declare class Node<T> {
2
- data: T;
3
- prev: Node<T> | null;
4
- next: Node<T> | null;
5
- constructor(data: Node<T>["data"]);
6
- forward(n: number): Node<T> | null;
7
- backward(n: number): Node<T> | null;
8
- }
9
- export declare class DoublyLinkedList<T> {
10
- static EMPTY_SIZE: number;
11
- private size;
12
- private head;
13
- private tail;
14
- getSize(): DoublyLinkedList<T>["size"];
15
- isEmpty(): boolean;
16
- getHead(): DoublyLinkedList<T>["head"];
17
- getTail(): DoublyLinkedList<T>["tail"];
18
- append(node: Node<T>): void;
19
- prepend(node: Node<T>): void;
20
- clear(): void;
21
- remove(node: Node<T>): void;
22
- insertAfter(node: Node<T>, target: Node<T>): void;
23
- insertBefore(node: Node<T>, target: Node<T>): void;
24
- find(callback: (node: Node<T>) => boolean): Node<T> | null;
25
- reverse(): void;
26
- toArray(): ReadonlyArray<Node<T>>;
27
- static fromArray<T>(array: ReadonlyArray<T>): DoublyLinkedList<T>;
28
- [Symbol.iterator](): IterableIterator<Node<T>>;
29
- }