@bgord/tools 1.3.24 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/age-years.vo.d.ts +3 -3
- package/dist/age-years.vo.js +4 -9
- package/dist/age.vo.js +2 -1
- package/dist/api-key.vo.d.ts +3 -4
- package/dist/api-key.vo.js +5 -9
- package/dist/basename.vo.d.ts +3 -3
- package/dist/basename.vo.js +10 -15
- package/dist/day-iso-id.vo.d.ts +3 -3
- package/dist/day-iso-id.vo.js +4 -8
- package/dist/day.vo.d.ts +1 -1
- package/dist/day.vo.js +7 -6
- package/dist/directory-path-absolute.vo.d.ts +3 -3
- package/dist/directory-path-absolute.vo.js +5 -12
- package/dist/directory-path-relative.vo.d.ts +3 -3
- package/dist/directory-path-relative.vo.js +5 -12
- package/dist/distance-value.vo.d.ts +3 -3
- package/dist/distance-value.vo.js +4 -8
- package/dist/distance.vo.js +7 -6
- package/dist/division-factor.vo.d.ts +3 -3
- package/dist/division-factor.vo.js +4 -7
- package/dist/duration-ms.vo.d.ts +3 -3
- package/dist/duration-ms.vo.js +4 -3
- package/dist/duration.service.js +2 -1
- package/dist/email.vo.d.ts +3 -3
- package/dist/email.vo.js +3 -3
- package/dist/etags.vo.js +3 -2
- package/dist/extension.vo.d.ts +3 -3
- package/dist/extension.vo.js +6 -12
- package/dist/feature-flag-value.vo.d.ts +3 -3
- package/dist/feature-flag-value.vo.js +2 -2
- package/dist/file-path-absolute-schema.vo.d.ts +8 -5
- package/dist/file-path-absolute-schema.vo.js +6 -13
- package/dist/file-path-relative-schema.vo.d.ts +8 -5
- package/dist/file-path-relative-schema.vo.js +6 -13
- package/dist/file-path.vo.js +5 -4
- package/dist/filename-affix.vo.d.ts +3 -3
- package/dist/filename-affix.vo.js +4 -9
- package/dist/filename-from-string.vo.d.ts +6 -6
- package/dist/filename-from-string.vo.js +5 -8
- package/dist/filename.vo.js +8 -7
- package/dist/height-milimiters.vo.d.ts +3 -3
- package/dist/height-milimiters.vo.js +4 -8
- package/dist/height.vo.js +4 -3
- package/dist/hour-value.vo.d.ts +3 -3
- package/dist/hour-value.vo.js +4 -9
- package/dist/hour.vo.js +3 -2
- package/dist/iban-schema.vo.d.ts +3 -3
- package/dist/iban-schema.vo.js +4 -9
- package/dist/iban.vo.js +2 -1
- package/dist/image.vo.d.ts +5 -5
- package/dist/image.vo.js +7 -17
- package/dist/integer-non-negative.vo.d.ts +3 -3
- package/dist/integer-non-negative.vo.js +4 -8
- package/dist/integer-positive.vo.d.ts +3 -3
- package/dist/integer-positive.vo.js +4 -8
- package/dist/integer.vo.d.ts +3 -3
- package/dist/integer.vo.js +3 -3
- package/dist/language.vo.d.ts +3 -3
- package/dist/language.vo.js +2 -2
- package/dist/mime-value.vo.d.ts +3 -2
- package/dist/mime-value.vo.js +4 -7
- package/dist/mime.vo.js +2 -1
- package/dist/mimes.js +12 -11
- package/dist/minute-value.vo.d.ts +3 -3
- package/dist/minute-value.vo.js +4 -9
- package/dist/minute.vo.js +3 -2
- package/dist/money-amount.vo.d.ts +3 -3
- package/dist/money-amount.vo.js +4 -8
- package/dist/money.vo.js +7 -6
- package/dist/month-iso-id.vo.d.ts +3 -3
- package/dist/month-iso-id.vo.js +5 -9
- package/dist/month.vo.js +5 -4
- package/dist/multiplication-factor.vo.d.ts +3 -3
- package/dist/multiplication-factor.vo.js +4 -7
- package/dist/object-key.vo.d.ts +3 -3
- package/dist/object-key.vo.js +8 -13
- package/dist/package-version-schema.vo.d.ts +3 -3
- package/dist/package-version-schema.vo.js +4 -7
- package/dist/package-version.vo.js +3 -4
- package/dist/pagination-page.vo.d.ts +3 -3
- package/dist/pagination-page.vo.js +2 -6
- package/dist/pagination-skip.vo.d.ts +3 -3
- package/dist/pagination-skip.vo.js +2 -5
- package/dist/pagination-take.vo.d.ts +3 -3
- package/dist/pagination-take.vo.js +2 -5
- package/dist/pagination.service.js +8 -7
- package/dist/quarter-iso-id.vo.d.ts +4 -3
- package/dist/quarter-iso-id.vo.js +7 -11
- package/dist/quarter.vo.js +3 -2
- package/dist/reordering-item-position-value.vo.d.ts +3 -3
- package/dist/reordering-item-position-value.vo.js +2 -5
- package/dist/reordering.service.d.ts +9 -9
- package/dist/reordering.service.js +7 -7
- package/dist/revision-value.vo.d.ts +3 -3
- package/dist/revision-value.vo.js +2 -5
- package/dist/revision.vo.js +3 -2
- package/dist/rounding-decimal.strategy.d.ts +2 -2
- package/dist/rounding-decimal.strategy.js +5 -10
- package/dist/size-bytes.vo.d.ts +3 -3
- package/dist/size-bytes.vo.js +4 -8
- package/dist/size.vo.js +5 -4
- package/dist/time-zone-offset-value.vo.d.ts +3 -3
- package/dist/time-zone-offset-value.vo.js +8 -12
- package/dist/timestamp-value.vo.d.ts +3 -3
- package/dist/timestamp-value.vo.js +4 -8
- package/dist/timestamp.vo.js +2 -1
- package/dist/timezone.vo.d.ts +3 -3
- package/dist/timezone.vo.js +7 -10
- package/dist/url-with-slash.vo.d.ts +3 -3
- package/dist/url-with-slash.vo.js +4 -7
- package/dist/url-without-slash.vo.d.ts +3 -3
- package/dist/url-without-slash.vo.js +4 -7
- package/dist/week-iso-id.vo.d.ts +3 -3
- package/dist/week-iso-id.vo.js +5 -9
- package/dist/week.vo.js +5 -4
- package/dist/weekday-iso-id.vo.d.ts +3 -3
- package/dist/weekday-iso-id.vo.js +4 -9
- package/dist/weekday.vo.js +9 -8
- package/dist/weight-grams.vo.d.ts +3 -3
- package/dist/weight-grams.vo.js +4 -8
- package/dist/weight.vo.js +8 -7
- package/dist/year-iso-id.vo.d.ts +3 -3
- package/dist/year-iso-id.vo.js +4 -7
- package/dist/year.vo.js +6 -5
- package/package.json +9 -12
package/dist/size-bytes.vo.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const SizeBytesError: {
|
|
3
3
|
Invalid: string;
|
|
4
4
|
};
|
|
5
|
-
export declare const SizeBytes:
|
|
6
|
-
export type SizeBytesType =
|
|
5
|
+
export declare const SizeBytes: v.SchemaWithPipe<readonly [v.NumberSchema<string>, v.IntegerAction<number, string>, v.MinValueAction<number, 0, string>, v.BrandAction<number, "SizeBytes">]>;
|
|
6
|
+
export type SizeBytesType = v.InferOutput<typeof SizeBytes>;
|
package/dist/size-bytes.vo.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const SizeBytesError = { Invalid: "size.bytes.invalid" };
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
.number(SizeBytesError.Invalid)
|
|
7
|
-
.int(SizeBytesError.Invalid)
|
|
8
|
-
.gte(0, SizeBytesError.Invalid)
|
|
9
|
-
.brand("SizeBytes");
|
|
3
|
+
export const SizeBytes = v.pipe(v.number(SizeBytesError.Invalid), v.integer(SizeBytesError.Invalid), v.minValue(0, SizeBytesError.Invalid),
|
|
4
|
+
// Stryker disable next-line StringLiteral
|
|
5
|
+
v.brand("SizeBytes"));
|
package/dist/size.vo.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
1
2
|
import { RoundingDecimalStrategy } from "./rounding-decimal.strategy";
|
|
2
3
|
import { RoundingUpStrategy } from "./rounding-up.strategy";
|
|
3
4
|
import { SizeBytes } from "./size-bytes.vo";
|
|
@@ -72,13 +73,13 @@ export class Size {
|
|
|
72
73
|
calculateBytes(value, unit) {
|
|
73
74
|
switch (unit) {
|
|
74
75
|
case SizeUnitEnum.kB:
|
|
75
|
-
return
|
|
76
|
+
return v.parse(SizeBytes, value * Size.KB_MULTIPLIER);
|
|
76
77
|
case SizeUnitEnum.MB:
|
|
77
|
-
return
|
|
78
|
+
return v.parse(SizeBytes, value * Size.MB_MULTIPLIER);
|
|
78
79
|
case SizeUnitEnum.GB:
|
|
79
|
-
return
|
|
80
|
+
return v.parse(SizeBytes, value * Size.GB_MULTIPLIER);
|
|
80
81
|
default:
|
|
81
|
-
return
|
|
82
|
+
return v.parse(SizeBytes, value);
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
toString() {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const TimeZoneOffsetValueError: {
|
|
3
3
|
Type: string;
|
|
4
4
|
Min: string;
|
|
5
5
|
Max: string;
|
|
6
6
|
};
|
|
7
|
-
export declare const TimeZoneOffsetValue:
|
|
8
|
-
export type TimeZoneOffsetValueType =
|
|
7
|
+
export declare const TimeZoneOffsetValue: v.SchemaWithPipe<readonly [v.UnknownSchema, v.TransformAction<unknown, number>, v.NumberSchema<string>, v.IntegerAction<number, string>, v.MinValueAction<number, -840, string>, v.MaxValueAction<number, 720, string>, v.BrandAction<number, "TimeZoneOffsetValue">]>;
|
|
8
|
+
export type TimeZoneOffsetValueType = v.InferOutput<typeof TimeZoneOffsetValue>;
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const TimeZoneOffsetValueError = {
|
|
3
3
|
Type: "time.zone.offset.value.type",
|
|
4
4
|
Min: "time.zone.offset.value.min",
|
|
5
5
|
Max: "time.zone.offset.value.max",
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// UTC-12 (Baker Island)
|
|
15
|
-
.max(720, TimeZoneOffsetValueError.Max)
|
|
16
|
-
.default(0) // Default to UTC if missing or invalid
|
|
17
|
-
.brand("TimeZoneOffsetValue");
|
|
7
|
+
export const TimeZoneOffsetValue = v.pipe(v.unknown(), v.transform((value) => (value === undefined ? 0 : Number(value))), v.number(TimeZoneOffsetValueError.Type), v.integer(TimeZoneOffsetValueError.Type),
|
|
8
|
+
// UTC+14 (Kiribati)
|
|
9
|
+
v.minValue(-840, TimeZoneOffsetValueError.Min),
|
|
10
|
+
// UTC-12 (Baker Island)
|
|
11
|
+
v.maxValue(720, TimeZoneOffsetValueError.Max),
|
|
12
|
+
// Stryker disable next-line StringLiteral
|
|
13
|
+
v.brand("TimeZoneOffsetValue"));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const TimestampValueError: {
|
|
3
3
|
Invalid: string;
|
|
4
4
|
};
|
|
5
|
-
export declare const TimestampValue:
|
|
6
|
-
export type TimestampValueType =
|
|
5
|
+
export declare const TimestampValue: v.SchemaWithPipe<readonly [v.NumberSchema<string>, v.IntegerAction<number, string>, v.MinValueAction<number, 0, string>, v.BrandAction<number, "TimestampValue">]>;
|
|
6
|
+
export type TimestampValueType = v.InferOutput<typeof TimestampValue>;
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const TimestampValueError = { Invalid: "timestamp.invalid" };
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
.number(TimestampValueError.Invalid)
|
|
7
|
-
.int(TimestampValueError.Invalid)
|
|
8
|
-
.gte(0, TimestampValueError.Invalid)
|
|
9
|
-
.brand("TimestampValue");
|
|
3
|
+
export const TimestampValue = v.pipe(v.number(TimestampValueError.Invalid), v.integer(TimestampValueError.Invalid), v.minValue(0, TimestampValueError.Invalid),
|
|
4
|
+
// Stryker disable next-line StringLiteral
|
|
5
|
+
v.brand("TimestampValue"));
|
package/dist/timestamp.vo.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
1
2
|
import { Duration } from "./duration.service";
|
|
2
3
|
import { TimestampValue } from "./timestamp-value.vo";
|
|
3
4
|
export class Timestamp {
|
|
@@ -9,7 +10,7 @@ export class Timestamp {
|
|
|
9
10
|
return new Timestamp(value);
|
|
10
11
|
}
|
|
11
12
|
static fromNumber(value) {
|
|
12
|
-
return new Timestamp(
|
|
13
|
+
return new Timestamp(v.parse(TimestampValue, value));
|
|
13
14
|
}
|
|
14
15
|
static fromDate(value) {
|
|
15
16
|
return Timestamp.fromNumber(value.getTime());
|
package/dist/timezone.vo.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const TimezoneError: {
|
|
3
3
|
Type: string;
|
|
4
4
|
Empty: string;
|
|
5
5
|
TooLong: string;
|
|
6
6
|
Invalid: string;
|
|
7
7
|
};
|
|
8
|
-
export declare const Timezone:
|
|
9
|
-
export type TimezoneType =
|
|
8
|
+
export declare const Timezone: v.SchemaWithPipe<readonly [v.StringSchema<string>, v.MinLengthAction<string, 1, string>, v.MaxLengthAction<string, 128, string>, v.CheckAction<string, string>, v.BrandAction<string, "Timezone">]>;
|
|
9
|
+
export type TimezoneType = v.InferOutput<typeof Timezone>;
|
package/dist/timezone.vo.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const TimezoneError = {
|
|
3
3
|
Type: "timezone.type",
|
|
4
4
|
Empty: "timezone.empty",
|
|
5
5
|
TooLong: "timezone.too.long",
|
|
6
6
|
Invalid: "timezone.invalid",
|
|
7
7
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// Stryker restore all
|
|
11
|
-
.string(TimezoneError.Type)
|
|
12
|
-
.min(1, TimezoneError.Empty)
|
|
13
|
-
.max(128, TimezoneError.TooLong)
|
|
14
|
-
.refine((value) => {
|
|
8
|
+
export const Timezone = v.pipe(v.string(TimezoneError.Type), v.minLength(1, TimezoneError.Empty), v.maxLength(128, TimezoneError.TooLong), v.check((value) => {
|
|
9
|
+
// Stryker disable all
|
|
15
10
|
try {
|
|
16
11
|
new Intl.DateTimeFormat("en-US", { timeZone: value }).format(Date.now());
|
|
17
12
|
return true;
|
|
@@ -19,5 +14,7 @@ export const Timezone = z
|
|
|
19
14
|
catch {
|
|
20
15
|
return false;
|
|
21
16
|
}
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
// Stryker restore all
|
|
18
|
+
}, TimezoneError.Invalid),
|
|
19
|
+
// Stryker disable next-line StringLiteral
|
|
20
|
+
v.brand("Timezone"));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const UrlWithSlashError: {
|
|
3
3
|
Invalid: string;
|
|
4
4
|
};
|
|
5
|
-
export declare const UrlWithSlash:
|
|
6
|
-
export type UrlWithSlashType =
|
|
5
|
+
export declare const UrlWithSlash: v.SchemaWithPipe<readonly [v.StringSchema<string>, v.UrlAction<string, string>, v.EndsWithAction<string, "/", string>, v.BrandAction<string, "UrlWithSlash">]>;
|
|
6
|
+
export type UrlWithSlashType = v.InferOutput<typeof UrlWithSlash>;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const UrlWithSlashError = { Invalid: "url.with.slash.invalid" };
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
.url(UrlWithSlashError.Invalid)
|
|
7
|
-
.refine((value) => value.endsWith("/"), UrlWithSlashError.Invalid)
|
|
8
|
-
.brand("UrlWithSlash");
|
|
3
|
+
export const UrlWithSlash = v.pipe(v.string(UrlWithSlashError.Invalid), v.url(UrlWithSlashError.Invalid), v.endsWith("/", UrlWithSlashError.Invalid),
|
|
4
|
+
// Stryker disable next-line StringLiteral
|
|
5
|
+
v.brand("UrlWithSlash"));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const UrlWithoutSlashError: {
|
|
3
3
|
Invalid: string;
|
|
4
4
|
};
|
|
5
|
-
export declare const UrlWithoutSlash:
|
|
6
|
-
export type UrlWithoutSlashType =
|
|
5
|
+
export declare const UrlWithoutSlash: v.SchemaWithPipe<readonly [v.StringSchema<string>, v.UrlAction<string, string>, v.CheckAction<string, string>, v.BrandAction<string, "UrlWithoutSlash">]>;
|
|
6
|
+
export type UrlWithoutSlashType = v.InferOutput<typeof UrlWithoutSlash>;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const UrlWithoutSlashError = { Invalid: "url.without.slash.invalid" };
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
.url(UrlWithoutSlashError.Invalid)
|
|
7
|
-
.refine((value) => !value.endsWith("/"), UrlWithoutSlashError.Invalid)
|
|
8
|
-
.brand("UrlWithoutSlash");
|
|
3
|
+
export const UrlWithoutSlash = v.pipe(v.string(UrlWithoutSlashError.Invalid), v.url(UrlWithoutSlashError.Invalid), v.check((value) => !value.endsWith("/"), UrlWithoutSlashError.Invalid),
|
|
4
|
+
// Stryker disable next-line StringLiteral
|
|
5
|
+
v.brand("UrlWithoutSlash"));
|
package/dist/week-iso-id.vo.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const WeekIsoIdError: {
|
|
3
3
|
Type: string;
|
|
4
4
|
BadChars: string;
|
|
5
5
|
Invalid: string;
|
|
6
6
|
};
|
|
7
|
-
export declare const WeekIsoId:
|
|
8
|
-
export type WeekIsoIdType =
|
|
7
|
+
export declare const WeekIsoId: v.SchemaWithPipe<readonly [v.StringSchema<string>, v.RegexAction<string, string>, v.CheckAction<string, string>, v.BrandAction<string, "WeekIsoId">]>;
|
|
8
|
+
export type WeekIsoIdType = v.InferOutput<typeof WeekIsoId>;
|
package/dist/week-iso-id.vo.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getISOWeeksInYear } from "date-fns";
|
|
2
|
-
import * as
|
|
2
|
+
import * as v from "valibot";
|
|
3
3
|
export const WeekIsoIdError = {
|
|
4
4
|
Type: "week.iso.id.type",
|
|
5
5
|
BadChars: "week.iso.id.bad.chars",
|
|
@@ -7,17 +7,13 @@ export const WeekIsoIdError = {
|
|
|
7
7
|
};
|
|
8
8
|
// Four digits, hypen, W, followed by two digits
|
|
9
9
|
const WEEK_ISO_ID_CHARS_WHITELIST = /^[0-9]{4}-W[0-9]{2}$/;
|
|
10
|
-
|
|
11
|
-
export const WeekIsoId = z
|
|
12
|
-
// Stryker restore all
|
|
13
|
-
.string(WeekIsoIdError.Type)
|
|
14
|
-
.regex(WEEK_ISO_ID_CHARS_WHITELIST, WeekIsoIdError.BadChars)
|
|
15
|
-
.refine((value) => {
|
|
10
|
+
export const WeekIsoId = v.pipe(v.string(WeekIsoIdError.Type), v.regex(WEEK_ISO_ID_CHARS_WHITELIST, WeekIsoIdError.BadChars), v.check((value) => {
|
|
16
11
|
const [year, week] = value.split("-W").map(Number);
|
|
17
12
|
// ISO-8601 rule: Jan 4 is always in week 01 of the ISO week-year.
|
|
18
13
|
const weeksInYear = getISOWeeksInYear(Date.UTC(year, 0, 4));
|
|
19
14
|
if (week < 1)
|
|
20
15
|
return false;
|
|
21
16
|
return week <= weeksInYear;
|
|
22
|
-
}, WeekIsoIdError.Invalid)
|
|
23
|
-
|
|
17
|
+
}, WeekIsoIdError.Invalid),
|
|
18
|
+
// Stryker disable next-line StringLiteral
|
|
19
|
+
v.brand("WeekIsoId"));
|
package/dist/week.vo.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { addWeeks, endOfISOWeek, getISOWeek, getISOWeekYear, startOfISOWeek } from "date-fns";
|
|
2
|
+
import * as v from "valibot";
|
|
2
3
|
import { DateRange } from "./date-range.vo";
|
|
3
4
|
import { Duration } from "./duration.service";
|
|
4
5
|
import { Integer } from "./integer.vo";
|
|
@@ -17,7 +18,7 @@ export class Week extends DateRange {
|
|
|
17
18
|
return Week.fromTimestamp(now);
|
|
18
19
|
}
|
|
19
20
|
static fromIsoId(isoId) {
|
|
20
|
-
const [year, week] =
|
|
21
|
+
const [year, week] = v.parse(WeekIsoId, isoId).split("-W").map(Number);
|
|
21
22
|
// ISO-8601 rule: Jan 4 is always in week 01 of the ISO week-year.
|
|
22
23
|
const januaryFourth = Timestamp.fromNumber(Date.UTC(year, 0, 4));
|
|
23
24
|
const firstWeekStart = Timestamp.fromNumber(startOfISOWeek(januaryFourth.ms).getTime());
|
|
@@ -26,13 +27,13 @@ export class Week extends DateRange {
|
|
|
26
27
|
toIsoId() {
|
|
27
28
|
const year = getISOWeekYear(this.getStart().ms);
|
|
28
29
|
const week = getISOWeek(this.getStart().ms);
|
|
29
|
-
return
|
|
30
|
+
return v.parse(WeekIsoId, `${year}-W${String(week).padStart(2, "0")}`);
|
|
30
31
|
}
|
|
31
32
|
previous() {
|
|
32
|
-
return this.shift(
|
|
33
|
+
return this.shift(v.parse(Integer, -1));
|
|
33
34
|
}
|
|
34
35
|
next() {
|
|
35
|
-
return this.shift(
|
|
36
|
+
return this.shift(v.parse(Integer, 1));
|
|
36
37
|
}
|
|
37
38
|
shift(count) {
|
|
38
39
|
const shifted = addWeeks(this.getStart().ms, count).getTime();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const WeekdayIsoIdError: {
|
|
3
3
|
Type: string;
|
|
4
4
|
Invalid: string;
|
|
5
5
|
};
|
|
6
|
-
export declare const WeekdayIsoId:
|
|
7
|
-
export type WeekdayIsoIdType =
|
|
6
|
+
export declare const WeekdayIsoId: v.SchemaWithPipe<readonly [v.NumberSchema<string>, v.IntegerAction<number, string>, v.MinValueAction<number, 1, string>, v.MaxValueAction<number, 7, string>, v.BrandAction<number, "WeekdayIsoId">]>;
|
|
7
|
+
export type WeekdayIsoIdType = v.InferOutput<typeof WeekdayIsoId>;
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const WeekdayIsoIdError = { Type: "weekday.iso.id.type", Invalid: "weekday.iso.id.invalid" };
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
.number(WeekdayIsoIdError.Type)
|
|
7
|
-
.int(WeekdayIsoIdError.Type)
|
|
8
|
-
.min(1, WeekdayIsoIdError.Invalid)
|
|
9
|
-
.max(7, WeekdayIsoIdError.Invalid)
|
|
10
|
-
.brand("WeekdayIsoId");
|
|
3
|
+
export const WeekdayIsoId = v.pipe(v.number(WeekdayIsoIdError.Type), v.integer(WeekdayIsoIdError.Type), v.minValue(1, WeekdayIsoIdError.Invalid), v.maxValue(7, WeekdayIsoIdError.Invalid),
|
|
4
|
+
// Stryker disable next-line StringLiteral
|
|
5
|
+
v.brand("WeekdayIsoId"));
|
package/dist/weekday.vo.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
1
2
|
import { Timestamp } from "./timestamp.vo";
|
|
2
3
|
import { WeekdayIsoId } from "./weekday-iso-id.vo";
|
|
3
4
|
export class Weekday {
|
|
4
5
|
value;
|
|
5
|
-
static MONDAY = Weekday.fromIsoId(
|
|
6
|
-
static TUESDAY = Weekday.fromIsoId(
|
|
7
|
-
static WEDNESDAY = Weekday.fromIsoId(
|
|
8
|
-
static THURSDAY = Weekday.fromIsoId(
|
|
9
|
-
static FRIDAY = Weekday.fromIsoId(
|
|
10
|
-
static SATURDAY = Weekday.fromIsoId(
|
|
11
|
-
static SUNDAY = Weekday.fromIsoId(
|
|
6
|
+
static MONDAY = Weekday.fromIsoId(v.parse(WeekdayIsoId, 1));
|
|
7
|
+
static TUESDAY = Weekday.fromIsoId(v.parse(WeekdayIsoId, 2));
|
|
8
|
+
static WEDNESDAY = Weekday.fromIsoId(v.parse(WeekdayIsoId, 3));
|
|
9
|
+
static THURSDAY = Weekday.fromIsoId(v.parse(WeekdayIsoId, 4));
|
|
10
|
+
static FRIDAY = Weekday.fromIsoId(v.parse(WeekdayIsoId, 5));
|
|
11
|
+
static SATURDAY = Weekday.fromIsoId(v.parse(WeekdayIsoId, 6));
|
|
12
|
+
static SUNDAY = Weekday.fromIsoId(v.parse(WeekdayIsoId, 7));
|
|
12
13
|
constructor(value) {
|
|
13
14
|
this.value = value;
|
|
14
15
|
}
|
|
15
16
|
static fromTimestamp(timestamp) {
|
|
16
17
|
// UTC returns numbers from 0-6, starting from Sunday
|
|
17
18
|
const utc = new Date(timestamp.ms).getUTCDay();
|
|
18
|
-
return new Weekday(
|
|
19
|
+
return new Weekday(v.parse(WeekdayIsoId, utc === 0 ? 7 : utc));
|
|
19
20
|
}
|
|
20
21
|
static fromTimestampValue(timestamp) {
|
|
21
22
|
return Weekday.fromTimestamp(Timestamp.fromValue(timestamp));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const WeightGramsError: {
|
|
3
3
|
Type: string;
|
|
4
4
|
Invalid: string;
|
|
5
5
|
};
|
|
6
|
-
export declare const WeightGrams:
|
|
7
|
-
export type WeightGramsType =
|
|
6
|
+
export declare const WeightGrams: v.SchemaWithPipe<readonly [v.NumberSchema<string>, v.IntegerAction<number, string>, v.MinValueAction<number, 0, string>, v.BrandAction<number, "WeightGrams">]>;
|
|
7
|
+
export type WeightGramsType = v.InferOutput<typeof WeightGrams>;
|
package/dist/weight-grams.vo.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const WeightGramsError = { Type: "weight.grams.type", Invalid: "weight.grams.invalid" };
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
.number(WeightGramsError.Type)
|
|
7
|
-
.int(WeightGramsError.Type)
|
|
8
|
-
.gte(0, WeightGramsError.Invalid)
|
|
9
|
-
.brand("WeightGrams");
|
|
3
|
+
export const WeightGrams = v.pipe(v.number(WeightGramsError.Type), v.integer(WeightGramsError.Type), v.minValue(0, WeightGramsError.Invalid),
|
|
4
|
+
// Stryker disable next-line StringLiteral
|
|
5
|
+
v.brand("WeightGrams"));
|
package/dist/weight.vo.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
1
2
|
import { RoundingToNearestStrategy } from "./rounding-to-nearest.strategy";
|
|
2
3
|
import { WeightGrams } from "./weight-grams.vo";
|
|
3
4
|
export class Weight {
|
|
@@ -10,13 +11,13 @@ export class Weight {
|
|
|
10
11
|
}
|
|
11
12
|
static fromKilograms(kilograms, rounding = new RoundingToNearestStrategy()) {
|
|
12
13
|
const grams = rounding.round(kilograms * Weight.GRAMS_PER_KILOGRAM);
|
|
13
|
-
return new Weight(
|
|
14
|
+
return new Weight(v.parse(WeightGrams, grams), rounding);
|
|
14
15
|
}
|
|
15
16
|
static fromGrams(grams, rounding = new RoundingToNearestStrategy()) {
|
|
16
|
-
return new Weight(
|
|
17
|
+
return new Weight(v.parse(WeightGrams, grams), rounding);
|
|
17
18
|
}
|
|
18
19
|
static zero() {
|
|
19
|
-
return new Weight(
|
|
20
|
+
return new Weight(v.parse(WeightGrams, 0));
|
|
20
21
|
}
|
|
21
22
|
get() {
|
|
22
23
|
return this.grams;
|
|
@@ -29,19 +30,19 @@ export class Weight {
|
|
|
29
30
|
return `${this.grams} g`;
|
|
30
31
|
}
|
|
31
32
|
add(other) {
|
|
32
|
-
return new Weight(
|
|
33
|
+
return new Weight(v.parse(WeightGrams, this.grams + other.grams));
|
|
33
34
|
}
|
|
34
35
|
subtract(other) {
|
|
35
36
|
const result = this.grams - other.grams;
|
|
36
|
-
return new Weight(
|
|
37
|
+
return new Weight(v.parse(WeightGrams, Math.max(0, result)), this.rounding);
|
|
37
38
|
}
|
|
38
39
|
multiply(factor) {
|
|
39
40
|
const grams = this.rounding.round(this.grams * factor);
|
|
40
|
-
return new Weight(
|
|
41
|
+
return new Weight(v.parse(WeightGrams, grams));
|
|
41
42
|
}
|
|
42
43
|
divide(divisor) {
|
|
43
44
|
const grams = this.rounding.round(this.grams / divisor);
|
|
44
|
-
return new Weight(
|
|
45
|
+
return new Weight(v.parse(WeightGrams, grams));
|
|
45
46
|
}
|
|
46
47
|
equals(other) {
|
|
47
48
|
return this.grams === other.grams;
|
package/dist/year-iso-id.vo.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export declare const YearIsoIdError: {
|
|
3
3
|
Type: string;
|
|
4
4
|
BadChars: string;
|
|
5
5
|
};
|
|
6
|
-
export declare const YearIsoId:
|
|
7
|
-
export type YearIsoIdType =
|
|
6
|
+
export declare const YearIsoId: v.SchemaWithPipe<readonly [v.StringSchema<string>, v.RegexAction<string, string>, v.BrandAction<string, "YearIsoId">]>;
|
|
7
|
+
export type YearIsoIdType = v.InferOutput<typeof YearIsoId>;
|
package/dist/year-iso-id.vo.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const YearIsoIdError = { Type: "year.iso.id.type", BadChars: "year.iso.id.bad.chars" };
|
|
3
3
|
// Four digits
|
|
4
4
|
const YEAR_ISO_ID_CHARS_WHITELIST = /^[0-9]{4}$/;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
.string(YearIsoIdError.Type)
|
|
9
|
-
.regex(YEAR_ISO_ID_CHARS_WHITELIST, YearIsoIdError.BadChars)
|
|
10
|
-
.brand("YearIsoId");
|
|
5
|
+
export const YearIsoId = v.pipe(v.string(YearIsoIdError.Type), v.regex(YEAR_ISO_ID_CHARS_WHITELIST, YearIsoIdError.BadChars),
|
|
6
|
+
// Stryker disable next-line StringLiteral
|
|
7
|
+
v.brand("YearIsoId"));
|
package/dist/year.vo.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { endOfYear, getYear, startOfYear } from "date-fns";
|
|
2
|
+
import * as v from "valibot";
|
|
2
3
|
import { DateRange } from "./date-range.vo";
|
|
3
4
|
import { Integer } from "./integer.vo";
|
|
4
5
|
import { Timestamp } from "./timestamp.vo";
|
|
@@ -16,14 +17,14 @@ export class Year extends DateRange {
|
|
|
16
17
|
return Year.fromTimestamp(now);
|
|
17
18
|
}
|
|
18
19
|
static fromNumber(candidate) {
|
|
19
|
-
return Year.fromIsoId(
|
|
20
|
+
return Year.fromIsoId(v.parse(YearIsoId, String(candidate)));
|
|
20
21
|
}
|
|
21
22
|
static fromIsoId(isoId) {
|
|
22
23
|
const year = Number(isoId);
|
|
23
24
|
return new Year(Timestamp.fromNumber(Date.UTC(year, 0, 1)), Timestamp.fromNumber(Date.UTC(year + 1, 0, 1) - 1));
|
|
24
25
|
}
|
|
25
26
|
toIsoId() {
|
|
26
|
-
return
|
|
27
|
+
return v.parse(YearIsoId, String(getYear(this.getStart().ms)));
|
|
27
28
|
}
|
|
28
29
|
isLeapYear() {
|
|
29
30
|
const year = getYear(this.getStart().ms);
|
|
@@ -34,14 +35,14 @@ export class Year extends DateRange {
|
|
|
34
35
|
return year % 4 === 0;
|
|
35
36
|
}
|
|
36
37
|
previous() {
|
|
37
|
-
return this.shift(
|
|
38
|
+
return this.shift(v.parse(Integer, -1));
|
|
38
39
|
}
|
|
39
40
|
next() {
|
|
40
|
-
return this.shift(
|
|
41
|
+
return this.shift(v.parse(Integer, 1));
|
|
41
42
|
}
|
|
42
43
|
shift(count) {
|
|
43
44
|
const year = getYear(this.getStart().ms) + count;
|
|
44
|
-
return Year.
|
|
45
|
+
return Year.fromNumber(year);
|
|
45
46
|
}
|
|
46
47
|
toString() {
|
|
47
48
|
return this.toIsoId();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bgord/tools",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Bartosz Gordon",
|
|
@@ -20,25 +20,22 @@
|
|
|
20
20
|
"preinstall": "bunx only-allow bun"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@biomejs/biome": "2.4.
|
|
24
|
-
"@commitlint/cli": "20.
|
|
25
|
-
"@commitlint/config-conventional": "20.
|
|
23
|
+
"@biomejs/biome": "2.4.7",
|
|
24
|
+
"@commitlint/cli": "20.5.0",
|
|
25
|
+
"@commitlint/config-conventional": "20.5.0",
|
|
26
26
|
"@stryker-mutator/core": "9.6.0",
|
|
27
27
|
"@types/bun": "1.3.10",
|
|
28
28
|
"cspell": "9.7.0",
|
|
29
|
-
"knip": "5.
|
|
30
|
-
"lefthook": "2.1.
|
|
29
|
+
"knip": "5.87.0",
|
|
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"
|
|
35
|
-
"zod": "4.3.6"
|
|
34
|
+
"typescript": "5.9.3"
|
|
36
35
|
},
|
|
37
36
|
"dependencies": {
|
|
38
|
-
"date-fns": "4.1.0"
|
|
39
|
-
|
|
40
|
-
"peerDependencies": {
|
|
41
|
-
"zod": "4.3.6"
|
|
37
|
+
"date-fns": "4.1.0",
|
|
38
|
+
"valibot": "1.2.0"
|
|
42
39
|
},
|
|
43
40
|
"sideEffects": false
|
|
44
41
|
}
|