@bgord/tools 0.17.2 → 1.0.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 +11 -0
- package/dist/age-years.vo.js +9 -0
- package/dist/age.vo.d.ts +11 -16
- package/dist/age.vo.js +20 -31
- package/dist/api-key.vo.d.ts +3 -1
- package/dist/api-key.vo.js +10 -5
- package/dist/basename.vo.d.ts +9 -9
- package/dist/basename.vo.js +22 -22
- package/dist/clock.vo.d.ts +10 -4
- package/dist/clock.vo.js +12 -14
- package/dist/date-calculator.service.d.ts +2 -1
- package/dist/date-formatter.service.d.ts +3 -4
- package/dist/date-range.vo.d.ts +7 -1
- package/dist/date-range.vo.js +5 -2
- package/dist/day-iso-id.vo.d.ts +5 -2
- package/dist/day-iso-id.vo.js +11 -7
- package/dist/day.vo.d.ts +4 -3
- package/dist/day.vo.js +18 -16
- package/dist/directory-path-absolute.vo.d.ts +10 -6
- package/dist/directory-path-absolute.vo.js +19 -17
- package/dist/directory-path-relative.vo.d.ts +10 -7
- package/dist/directory-path-relative.vo.js +18 -17
- package/dist/division-factor.vo.d.ts +7 -0
- package/dist/division-factor.vo.js +9 -0
- package/dist/duration-ms.vo.d.ts +6 -0
- package/dist/duration-ms.vo.js +3 -0
- package/dist/duration.service.d.ts +2 -14
- package/dist/duration.service.js +16 -35
- package/dist/email-mask.service.d.ts +1 -6
- package/dist/email-mask.service.js +6 -8
- package/dist/etags.vo.d.ts +4 -3
- package/dist/etags.vo.js +3 -3
- package/dist/extension.vo.d.ts +6 -4
- package/dist/extension.vo.js +15 -10
- package/dist/feature-flag-value.vo.d.ts +10 -0
- package/dist/feature-flag-value.vo.js +8 -0
- package/dist/feature-flag.vo.d.ts +1 -7
- package/dist/feature-flag.vo.js +1 -7
- package/dist/file-path-absolute-schema.vo.d.ts +10 -7
- package/dist/file-path-absolute-schema.vo.js +17 -17
- package/dist/file-path-relative-schema.vo.d.ts +10 -7
- package/dist/file-path-relative-schema.vo.js +14 -12
- package/dist/file-path.vo.d.ts +4 -4
- package/dist/file-path.vo.js +8 -8
- package/dist/filename-from-string.vo.d.ts +4 -2
- package/dist/filename-from-string.vo.js +10 -8
- package/dist/filename-suffix.vo.d.ts +7 -3
- package/dist/filename-suffix.vo.js +13 -7
- package/dist/filename.vo.d.ts +2 -0
- package/dist/filename.vo.js +8 -2
- package/dist/height-milimiters.vo.d.ts +6 -0
- package/dist/height-milimiters.vo.js +10 -0
- package/dist/height.vo.d.ts +3 -20
- package/dist/height.vo.js +11 -62
- package/dist/hour-format.service.js +1 -1
- package/dist/hour-schema.vo.d.ts +7 -0
- package/dist/hour-schema.vo.js +8 -0
- package/dist/hour.vo.d.ts +4 -3
- package/dist/hour.vo.js +8 -8
- package/dist/iban-mask.service.d.ts +1 -3
- package/dist/iban-mask.service.js +2 -2
- package/dist/iban-schema.vo.d.ts +7 -0
- package/dist/iban-schema.vo.js +10 -0
- package/dist/iban.vo.d.ts +4 -10
- package/dist/iban.vo.js +6 -13
- package/dist/image.vo.d.ts +6 -4
- package/dist/image.vo.js +13 -12
- package/dist/index.d.ts +24 -2
- package/dist/index.js +24 -2
- package/dist/language.vo.d.ts +2 -1
- package/dist/language.vo.js +6 -4
- package/dist/linear-regression.service.d.ts +27 -0
- package/dist/{simple-linear-regression.service.js → linear-regression.service.js} +17 -15
- package/dist/mean.service.d.ts +3 -1
- package/dist/mean.service.js +3 -4
- package/dist/mime-types.vo.d.ts +1 -2
- package/dist/mime-value.vo.d.ts +9 -0
- package/dist/mime-value.vo.js +9 -0
- package/dist/mime.vo.d.ts +11 -17
- package/dist/mime.vo.js +10 -27
- package/dist/min-max-scaler.service.d.ts +7 -5
- package/dist/min-max-scaler.service.js +12 -10
- package/dist/minute-schema.vo.d.ts +7 -0
- package/dist/minute-schema.vo.js +8 -0
- package/dist/minute.vo.d.ts +4 -3
- package/dist/minute.vo.js +8 -8
- package/dist/money-amount.vo.d.ts +7 -0
- package/dist/money-amount.vo.js +7 -0
- package/dist/money.vo.d.ts +9 -18
- package/dist/money.vo.js +14 -27
- package/dist/month-iso-id.vo.d.ts +4 -2
- package/dist/month-iso-id.vo.js +13 -7
- package/dist/month.vo.d.ts +4 -3
- package/dist/month.vo.js +21 -21
- package/dist/multiplication-factor.vo.d.ts +7 -0
- package/dist/multiplication-factor.vo.js +9 -0
- package/dist/object-key.vo.d.ts +9 -6
- package/dist/object-key.vo.js +20 -19
- package/dist/outlier-detector.service.d.ts +3 -1
- package/dist/outlier-detector.service.js +2 -2
- package/dist/package-version-schema.vo.d.ts +11 -0
- package/dist/package-version-schema.vo.js +15 -0
- package/dist/package-version.vo.d.ts +11 -20
- package/dist/package-version.vo.js +11 -20
- package/dist/pagination-page.vo.d.ts +6 -0
- package/dist/pagination-page.vo.js +7 -0
- package/dist/pagination-skip.vo.d.ts +7 -0
- package/dist/pagination-skip.vo.js +9 -0
- package/dist/pagination-take.vo.d.ts +7 -0
- package/dist/pagination-take.vo.js +9 -0
- package/dist/pagination.service.d.ts +3 -8
- package/dist/pagination.service.js +5 -12
- package/dist/percentage.service.d.ts +3 -1
- package/dist/percentage.service.js +2 -2
- package/dist/population-standard-deviation.service.d.ts +3 -1
- package/dist/population-standard-deviation.service.js +5 -4
- package/dist/quarter-iso-id.vo.d.ts +3 -2
- package/dist/quarter-iso-id.vo.js +7 -9
- package/dist/quarter.vo.d.ts +2 -1
- package/dist/quarter.vo.js +10 -7
- package/dist/random.service.d.ts +3 -4
- package/dist/random.service.js +5 -11
- package/dist/rate-limiter.service.d.ts +2 -2
- package/dist/rate-limiter.service.js +8 -8
- package/dist/reordering-item-position-value.vo.d.ts +6 -0
- package/dist/reordering-item-position-value.vo.js +6 -0
- package/dist/reordering.service.d.ts +7 -23
- package/dist/reordering.service.js +15 -24
- package/dist/revision-value.vo.d.ts +7 -0
- package/dist/revision-value.vo.js +6 -0
- package/dist/revision.vo.d.ts +6 -13
- package/dist/revision.vo.js +10 -22
- package/dist/rounding.adapter.d.ts +7 -2
- package/dist/rounding.adapter.js +13 -5
- package/dist/size-bytes.vo.d.ts +6 -0
- package/dist/size-bytes.vo.js +7 -0
- package/dist/size.vo.d.ts +15 -15
- package/dist/size.vo.js +41 -51
- package/dist/stopwatch.service.d.ts +3 -1
- package/dist/stopwatch.service.js +2 -2
- package/dist/sum.service.js +8 -8
- package/dist/thousands-separator.service.js +4 -1
- package/dist/time.service.d.ts +8 -0
- package/dist/time.service.js +13 -0
- package/dist/timestamp.vo.d.ts +1 -1
- package/dist/timestamp.vo.js +4 -5
- package/dist/timezone.vo.d.ts +4 -1
- package/dist/timezone.vo.js +12 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/week-iso-id.vo.d.ts +4 -2
- package/dist/week-iso-id.vo.js +15 -9
- package/dist/week.vo.d.ts +4 -3
- package/dist/week.vo.js +21 -22
- package/dist/weekday.vo.d.ts +1 -1
- package/dist/weekday.vo.js +6 -8
- package/dist/weight-grams.vo.d.ts +7 -0
- package/dist/weight-grams.vo.js +7 -0
- package/dist/weight.vo.d.ts +12 -35
- package/dist/weight.vo.js +23 -72
- package/dist/year-iso-id.vo.d.ts +3 -2
- package/dist/year-iso-id.vo.js +6 -4
- package/dist/year.vo.d.ts +5 -6
- package/dist/year.vo.js +21 -26
- package/dist/z-score.service.d.ts +3 -1
- package/dist/z-score.service.js +2 -2
- package/package.json +4 -4
- package/readme.md +21 -2
- package/src/age-years.vo.ts +14 -0
- package/src/age.vo.ts +22 -35
- package/src/api-key.vo.ts +11 -5
- package/src/basename.vo.ts +24 -22
- package/src/clock.vo.ts +16 -17
- package/src/date-calculator.service.ts +2 -1
- package/src/date-formatter.service.ts +4 -5
- package/src/date-range.vo.ts +6 -2
- package/src/day-iso-id.vo.ts +12 -8
- package/src/day.vo.ts +27 -24
- package/src/directory-path-absolute.vo.ts +23 -18
- package/src/directory-path-relative.vo.ts +21 -18
- package/src/division-factor.vo.ts +13 -0
- package/src/duration-ms.vo.ts +7 -0
- package/src/duration.service.ts +16 -40
- package/src/email-mask.service.ts +7 -15
- package/src/etags.vo.ts +4 -5
- package/src/extension.vo.ts +17 -10
- package/src/feature-flag-value.vo.ts +12 -0
- package/src/feature-flag.vo.ts +1 -9
- package/src/file-path-absolute-schema.vo.ts +18 -17
- package/src/file-path-relative-schema.vo.ts +15 -12
- package/src/file-path.vo.ts +8 -8
- package/src/filename-from-string.vo.ts +12 -9
- package/src/filename-suffix.vo.ts +14 -7
- package/src/filename.vo.ts +11 -2
- package/src/height-milimiters.vo.ts +12 -0
- package/src/height.vo.ts +12 -83
- package/src/hour-format.service.ts +2 -1
- package/src/hour-schema.vo.ts +12 -0
- package/src/hour.vo.ts +12 -12
- package/src/iban-mask.service.ts +3 -5
- package/src/iban-schema.vo.ts +15 -0
- package/src/iban.vo.ts +9 -22
- package/src/image.vo.ts +14 -12
- package/src/index.ts +24 -2
- package/src/language.vo.ts +7 -4
- package/src/linear-regression.service.ts +71 -0
- package/src/mean.service.ts +3 -5
- package/src/mime-types.vo.ts +1 -3
- package/src/mime-value.vo.ts +12 -0
- package/src/mime.vo.ts +12 -33
- package/src/min-max-scaler.service.ts +13 -11
- package/src/minute-schema.vo.ts +12 -0
- package/src/minute.vo.ts +12 -12
- package/src/money-amount.vo.ts +11 -0
- package/src/money.vo.ts +20 -38
- package/src/month-iso-id.vo.ts +14 -7
- package/src/month.vo.ts +25 -24
- package/src/multiplication-factor.vo.ts +13 -0
- package/src/object-key.vo.ts +25 -21
- package/src/outlier-detector.service.ts +2 -2
- package/src/package-version-schema.vo.ts +21 -0
- package/src/package-version.vo.ts +17 -33
- package/src/pagination-page.vo.ts +11 -0
- package/src/pagination-skip.vo.ts +13 -0
- package/src/pagination-take.vo.ts +13 -0
- package/src/pagination.service.ts +5 -22
- package/src/percentage.service.ts +2 -2
- package/src/population-standard-deviation.service.ts +5 -4
- package/src/quarter-iso-id.vo.ts +7 -10
- package/src/quarter.vo.ts +14 -9
- package/src/random.service.ts +6 -9
- package/src/rate-limiter.service.ts +9 -8
- package/src/reordering-item-position-value.vo.ts +10 -0
- package/src/reordering.service.ts +19 -28
- package/src/revision-value.vo.ts +10 -0
- package/src/revision.vo.ts +10 -25
- package/src/rounding.adapter.ts +16 -3
- package/src/size-bytes.vo.ts +11 -0
- package/src/size.vo.ts +43 -54
- package/src/stopwatch.service.ts +3 -3
- package/src/sum.service.ts +8 -8
- package/src/thousands-separator.service.ts +4 -1
- package/src/time.service.ts +15 -0
- package/src/timestamp.vo.ts +4 -5
- package/src/timezone.vo.ts +12 -6
- package/src/week-iso-id.vo.ts +16 -12
- package/src/week.vo.ts +26 -28
- package/src/weekday.vo.ts +6 -9
- package/src/weight-grams.vo.ts +11 -0
- package/src/weight.vo.ts +28 -85
- package/src/year-iso-id.vo.ts +7 -4
- package/src/year.vo.ts +27 -33
- package/src/z-score.service.ts +2 -2
- package/dist/simple-linear-regression.service.d.ts +0 -25
- package/dist/streak-calculator.service.d.ts +0 -13
- package/dist/streak-calculator.service.js +0 -22
- package/src/simple-linear-regression.service.ts +0 -69
- package/src/streak-calculator.service.ts +0 -32
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type TimestampType } from "./timestamp.vo";
|
|
3
|
-
export declare const DurationMsError: {
|
|
4
|
-
readonly error: "duration.invalid";
|
|
5
|
-
};
|
|
6
|
-
export declare const DurationMsSchema: z.core.$ZodBranded<z.ZodNumber, "DurationMs">;
|
|
7
|
-
export type DurationMsType = z.infer<typeof DurationMsSchema>;
|
|
1
|
+
import { type DurationMsType } from "./duration-ms.vo";
|
|
8
2
|
export declare class Duration {
|
|
9
3
|
private static readonly rounding;
|
|
10
|
-
private readonly
|
|
4
|
+
private readonly internal;
|
|
11
5
|
private static readonly MS_IN_SECOND;
|
|
12
6
|
private static readonly MS_IN_MINUTE;
|
|
13
7
|
private static readonly MS_IN_HOUR;
|
|
@@ -29,9 +23,3 @@ export declare class Duration {
|
|
|
29
23
|
add(another: Duration): Duration;
|
|
30
24
|
subtract(another: Duration): Duration;
|
|
31
25
|
}
|
|
32
|
-
export declare const Time: {
|
|
33
|
-
Now(now: TimestampType): {
|
|
34
|
-
Add(duration: Duration): TimestampType;
|
|
35
|
-
Minus(duration: Duration): TimestampType;
|
|
36
|
-
};
|
|
37
|
-
};
|
package/dist/duration.service.js
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DurationMs } from "./duration-ms.vo";
|
|
2
2
|
import { RoundToDecimal } from "./rounding.adapter";
|
|
3
|
-
import { Timestamp } from "./timestamp.vo";
|
|
4
|
-
export const DurationMsError = { error: "duration.invalid" };
|
|
5
|
-
export const DurationMsSchema = z
|
|
6
|
-
.number(DurationMsError)
|
|
7
|
-
.int(DurationMsError)
|
|
8
|
-
.refine(Number.isFinite, DurationMsError)
|
|
9
|
-
.brand("DurationMs");
|
|
10
3
|
export class Duration {
|
|
11
4
|
static rounding = new RoundToDecimal(2);
|
|
12
|
-
|
|
5
|
+
internal;
|
|
13
6
|
static MS_IN_SECOND = 1_000;
|
|
14
|
-
static MS_IN_MINUTE =
|
|
15
|
-
static MS_IN_HOUR =
|
|
16
|
-
static MS_IN_DAY =
|
|
7
|
+
static MS_IN_MINUTE = 60 * Duration.MS_IN_SECOND;
|
|
8
|
+
static MS_IN_HOUR = 60 * Duration.MS_IN_MINUTE;
|
|
9
|
+
static MS_IN_DAY = 24 * Duration.MS_IN_HOUR;
|
|
17
10
|
constructor(candidateMs) {
|
|
18
|
-
this.
|
|
11
|
+
this.internal = DurationMs.parse(candidateMs);
|
|
19
12
|
}
|
|
20
13
|
static Days(value) {
|
|
21
14
|
return new Duration(value * Duration.MS_IN_DAY);
|
|
@@ -33,45 +26,33 @@ export class Duration {
|
|
|
33
26
|
return new Duration(value);
|
|
34
27
|
}
|
|
35
28
|
get days() {
|
|
36
|
-
return Duration.rounding.round(this.
|
|
29
|
+
return Duration.rounding.round(this.internal / Duration.MS_IN_DAY);
|
|
37
30
|
}
|
|
38
31
|
get hours() {
|
|
39
|
-
return Duration.rounding.round(this.
|
|
32
|
+
return Duration.rounding.round(this.internal / Duration.MS_IN_HOUR);
|
|
40
33
|
}
|
|
41
34
|
get minutes() {
|
|
42
|
-
return Duration.rounding.round(this.
|
|
35
|
+
return Duration.rounding.round(this.internal / Duration.MS_IN_MINUTE);
|
|
43
36
|
}
|
|
44
37
|
get seconds() {
|
|
45
|
-
return Duration.rounding.round(this.
|
|
38
|
+
return Duration.rounding.round(this.internal / Duration.MS_IN_SECOND);
|
|
46
39
|
}
|
|
47
40
|
get ms() {
|
|
48
|
-
return this.
|
|
41
|
+
return this.internal;
|
|
49
42
|
}
|
|
50
43
|
isLongerThan(another) {
|
|
51
|
-
return this.
|
|
44
|
+
return this.internal > another.internal;
|
|
52
45
|
}
|
|
53
46
|
isShorterThan(another) {
|
|
54
|
-
return this.
|
|
47
|
+
return this.internal < another.internal;
|
|
55
48
|
}
|
|
56
49
|
equals(other) {
|
|
57
|
-
return this.
|
|
50
|
+
return this.internal === other.internal;
|
|
58
51
|
}
|
|
59
52
|
add(another) {
|
|
60
|
-
return Duration.Ms(this.
|
|
53
|
+
return Duration.Ms(this.internal + another.internal);
|
|
61
54
|
}
|
|
62
55
|
subtract(another) {
|
|
63
|
-
return Duration.Ms(this.
|
|
56
|
+
return Duration.Ms(this.internal - another.internal);
|
|
64
57
|
}
|
|
65
58
|
}
|
|
66
|
-
export const Time = {
|
|
67
|
-
Now(now) {
|
|
68
|
-
return {
|
|
69
|
-
Add(duration) {
|
|
70
|
-
return Timestamp.parse(now + duration.ms);
|
|
71
|
-
},
|
|
72
|
-
Minus(duration) {
|
|
73
|
-
return Timestamp.parse(now - duration.ms);
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
},
|
|
77
|
-
};
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import { z } from "zod/v4";
|
|
2
|
-
export declare const Email: z.core.$ZodBranded<z.ZodEmail, "Email">;
|
|
3
|
-
export type EmailType = z.infer<typeof Email>;
|
|
4
|
-
type EmailMaskedType = string;
|
|
5
1
|
export declare class EmailMask {
|
|
6
|
-
static censor(email:
|
|
2
|
+
static censor(email: string): string;
|
|
7
3
|
}
|
|
8
|
-
export {};
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { z } from "zod/v4";
|
|
2
|
-
export const Email = z.email().brand("Email");
|
|
3
1
|
export class EmailMask {
|
|
4
2
|
static censor(email) {
|
|
5
|
-
const [
|
|
6
|
-
|
|
7
|
-
const domain = afterAt;
|
|
8
|
-
if (local.length <= 2) {
|
|
3
|
+
const [local, domain] = email.split("@");
|
|
4
|
+
if (local.length <= 2)
|
|
9
5
|
return `${"*".repeat(local.length)}@${domain}`;
|
|
10
|
-
|
|
11
|
-
const
|
|
6
|
+
const firstCharacter = local.at(0);
|
|
7
|
+
const censoredPart = "*".repeat(local.length - 2);
|
|
8
|
+
const lastCharacter = local.at(-1);
|
|
9
|
+
const censoredLocal = `${firstCharacter}${censoredPart}${lastCharacter}`;
|
|
12
10
|
return `${censoredLocal}@${domain}`;
|
|
13
11
|
}
|
|
14
12
|
}
|
package/dist/etags.vo.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const RevisionValue: z.ZodNumber;
|
|
3
|
-
type RevisionValueType = z.infer<typeof RevisionValue>;
|
|
1
|
+
import { type RevisionValueType } from "./revision-value.vo";
|
|
4
2
|
type ETagValueType = string;
|
|
5
3
|
export declare class ETag {
|
|
6
4
|
readonly revision: RevisionValueType;
|
|
@@ -11,6 +9,9 @@ export declare class ETag {
|
|
|
11
9
|
static fromHeader(value?: ETagValueType): ETag | null;
|
|
12
10
|
}
|
|
13
11
|
export type WeakETagValueType = string;
|
|
12
|
+
export declare const WeakETagError: {
|
|
13
|
+
readonly Invalid: "weak.etag.invalid";
|
|
14
|
+
};
|
|
14
15
|
export declare class WeakETag {
|
|
15
16
|
readonly revision: RevisionValueType;
|
|
16
17
|
static HEADER_NAME: string;
|
package/dist/etags.vo.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const RevisionValue = z.number().int().min(0);
|
|
1
|
+
import { RevisionValue } from "./revision-value.vo";
|
|
3
2
|
export class ETag {
|
|
4
3
|
revision;
|
|
5
4
|
static HEADER_NAME = "ETag";
|
|
@@ -18,6 +17,7 @@ export class ETag {
|
|
|
18
17
|
return new ETag(RevisionValue.parse(candidate));
|
|
19
18
|
}
|
|
20
19
|
}
|
|
20
|
+
export const WeakETagError = { Invalid: "weak.etag.invalid" };
|
|
21
21
|
export class WeakETag {
|
|
22
22
|
revision;
|
|
23
23
|
static HEADER_NAME = "ETag";
|
|
@@ -29,7 +29,7 @@ export class WeakETag {
|
|
|
29
29
|
}
|
|
30
30
|
static fromHeader(value) {
|
|
31
31
|
if (!value?.startsWith("W/"))
|
|
32
|
-
throw Error(
|
|
32
|
+
throw new Error(WeakETagError.Invalid);
|
|
33
33
|
const candidate = Number(value.split("W/")[1]);
|
|
34
34
|
if (Number.isNaN(candidate))
|
|
35
35
|
return null;
|
package/dist/extension.vo.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export declare const ExtensionError: {
|
|
3
|
+
readonly Type: "extension.type";
|
|
4
|
+
readonly Empty: "extension.empty";
|
|
5
|
+
readonly TooLong: "extension.too.long";
|
|
6
|
+
readonly BadChars: "extension.bad.chars";
|
|
7
|
+
};
|
|
6
8
|
export declare const Extension: z.core.$ZodBranded<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, "Extension">;
|
|
7
9
|
export type ExtensionType = z.infer<typeof Extension>;
|
package/dist/extension.vo.js
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export const ExtensionError = {
|
|
3
|
+
Type: "extension.type",
|
|
4
|
+
Empty: "extension.empty",
|
|
5
|
+
TooLong: "extension.too.long",
|
|
6
|
+
BadChars: "extension.bad.chars",
|
|
7
|
+
};
|
|
8
|
+
// Lowercase letters and digits allowed
|
|
9
|
+
const EXTENSION_WHITELIST = /^[a-z0-9]+$/;
|
|
10
|
+
const LEADING_DOT_FILE = /^\./;
|
|
6
11
|
export const Extension = z
|
|
7
|
-
.string(
|
|
8
|
-
.trim()
|
|
12
|
+
.string(ExtensionError.Type)
|
|
9
13
|
.toLowerCase()
|
|
10
|
-
.
|
|
11
|
-
.
|
|
12
|
-
|
|
13
|
-
.
|
|
14
|
+
.min(2, ExtensionError.Empty)
|
|
15
|
+
.max(16, ExtensionError.TooLong)
|
|
16
|
+
// Transform ".png" -> "png"
|
|
17
|
+
.transform((value) => value.replace(LEADING_DOT_FILE, ""))
|
|
18
|
+
.refine((value) => EXTENSION_WHITELIST.test(value), ExtensionError.BadChars)
|
|
14
19
|
.brand("Extension");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export declare const FeatureFlagValueError: {
|
|
3
|
+
readonly Invalid: "feature.flag.value.invalid";
|
|
4
|
+
};
|
|
5
|
+
export declare enum FeatureFlagEnum {
|
|
6
|
+
yes = "yes",
|
|
7
|
+
no = "no"
|
|
8
|
+
}
|
|
9
|
+
export declare const FeatureFlagValue: z.ZodEnum<typeof FeatureFlagEnum>;
|
|
10
|
+
export type FeatureFlagValueType = z.infer<typeof FeatureFlagValue>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export const FeatureFlagValueError = { Invalid: "feature.flag.value.invalid" };
|
|
3
|
+
export var FeatureFlagEnum;
|
|
4
|
+
(function (FeatureFlagEnum) {
|
|
5
|
+
FeatureFlagEnum["yes"] = "yes";
|
|
6
|
+
FeatureFlagEnum["no"] = "no";
|
|
7
|
+
})(FeatureFlagEnum || (FeatureFlagEnum = {}));
|
|
8
|
+
export const FeatureFlagValue = z.enum(FeatureFlagEnum, FeatureFlagValueError.Invalid);
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare enum FeatureFlagEnum {
|
|
3
|
-
yes = "yes",
|
|
4
|
-
no = "no"
|
|
5
|
-
}
|
|
6
|
-
export declare const FeatureFlagValue: z.ZodEnum<typeof FeatureFlagEnum>;
|
|
7
|
-
export type FeatureFlagValueType = z.infer<typeof FeatureFlagValue>;
|
|
1
|
+
import { type FeatureFlagValueType } from "./feature-flag-value.vo";
|
|
8
2
|
export declare class FeatureFlag {
|
|
9
3
|
static isEnabled(flag: FeatureFlagValueType): boolean;
|
|
10
4
|
static isDisabled(flag: FeatureFlagValueType): boolean;
|
package/dist/feature-flag.vo.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export var FeatureFlagEnum;
|
|
3
|
-
(function (FeatureFlagEnum) {
|
|
4
|
-
FeatureFlagEnum["yes"] = "yes";
|
|
5
|
-
FeatureFlagEnum["no"] = "no";
|
|
6
|
-
})(FeatureFlagEnum || (FeatureFlagEnum = {}));
|
|
7
|
-
export const FeatureFlagValue = z.enum(FeatureFlagEnum);
|
|
1
|
+
import { FeatureFlagEnum } from "./feature-flag-value.vo";
|
|
8
2
|
export class FeatureFlag {
|
|
9
3
|
static isEnabled(flag) {
|
|
10
4
|
return flag === FeatureFlagEnum.yes;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
2
|
import { Filename } from "./filename.vo";
|
|
3
|
-
export declare const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
export declare const FilePathAbsoluteSchemaError: {
|
|
4
|
+
readonly Type: "file.path.absolute.type";
|
|
5
|
+
readonly LeadingSlash: "file.path.absolute.leading.slash";
|
|
6
|
+
readonly TrailingSlash: "file.path.absolute.trailing.slash";
|
|
7
|
+
readonly BackslashForbidden: "file.path.absolute.backslash.forbidden";
|
|
8
|
+
readonly Empty: "file.path.absolute.empty";
|
|
9
|
+
};
|
|
10
|
+
export declare const FilePathAbsoluteSchema: z.core.$ZodBranded<z.ZodPipe<z.ZodString, z.ZodTransform<{
|
|
11
|
+
directory: string & z.core.$brand<"DirectoryPathAbsoluteSchema">;
|
|
9
12
|
filename: Filename;
|
|
10
|
-
}, string
|
|
13
|
+
}, string>>, "FilePathAbsoluteSchema">;
|
|
11
14
|
export type FilePathAbsoluteType = z.infer<typeof FilePathAbsoluteSchema>;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
2
|
import { DirectoryPathAbsoluteSchema } from "./directory-path-absolute.vo";
|
|
3
3
|
import { Filename } from "./filename.vo";
|
|
4
|
-
export const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
export const FilePathAbsoluteSchemaError = {
|
|
5
|
+
Type: "file.path.absolute.type",
|
|
6
|
+
LeadingSlash: "file.path.absolute.leading.slash",
|
|
7
|
+
TrailingSlash: "file.path.absolute.trailing.slash",
|
|
8
|
+
BackslashForbidden: "file.path.absolute.backslash.forbidden",
|
|
9
|
+
Empty: "file.path.absolute.empty",
|
|
10
|
+
};
|
|
8
11
|
export const FilePathAbsoluteSchema = z
|
|
9
|
-
.string(
|
|
10
|
-
.
|
|
11
|
-
.refine((value) => value.startsWith("/"),
|
|
12
|
-
.refine((value) => !value.
|
|
13
|
-
|
|
14
|
-
.transform((value) => value.replace(/\/{2,}/g, "/"))
|
|
15
|
-
// keep "/" as-is; otherwise remove a trailing slash
|
|
16
|
-
.transform((value) => (value !== "/" && value.endsWith("/") ? value.slice(0, -1) : value))
|
|
17
|
-
.refine((value) => value !== "/", AbsFilePathMissingFilenameError)
|
|
12
|
+
.string(FilePathAbsoluteSchemaError.Type)
|
|
13
|
+
.min(1, FilePathAbsoluteSchemaError.Empty)
|
|
14
|
+
.refine((value) => value.startsWith("/"), FilePathAbsoluteSchemaError.LeadingSlash)
|
|
15
|
+
.refine((value) => !value.endsWith("/"), FilePathAbsoluteSchemaError.TrailingSlash)
|
|
16
|
+
.refine((value) => !value.includes("\\"), FilePathAbsoluteSchemaError.BackslashForbidden)
|
|
18
17
|
.transform((normalized) => {
|
|
19
|
-
const
|
|
20
|
-
const directoryCandidate =
|
|
21
|
-
const filenameCandidate = normalized.slice(
|
|
18
|
+
const index = normalized.lastIndexOf("/");
|
|
19
|
+
const directoryCandidate = index === 0 ? "/" : normalized.slice(0, index);
|
|
20
|
+
const filenameCandidate = normalized.slice(index + 1);
|
|
22
21
|
const directory = DirectoryPathAbsoluteSchema.parse(directoryCandidate);
|
|
23
22
|
const filename = Filename.fromString(filenameCandidate);
|
|
24
23
|
return { directory, filename };
|
|
25
|
-
})
|
|
24
|
+
})
|
|
25
|
+
.brand("FilePathAbsoluteSchema");
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
2
|
import { Filename } from "./filename.vo";
|
|
3
|
-
export declare const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
export declare const FilePathRelativeSchemaError: {
|
|
4
|
+
readonly Type: "file.path.relative.type";
|
|
5
|
+
readonly LeadingSlash: "file.path.relative.leading.slash";
|
|
6
|
+
readonly BackslashForbidden: "file.path.relative.backslash.forbidden";
|
|
7
|
+
readonly RequiresDirectory: "file.path.relative.requires.directory";
|
|
8
|
+
readonly Empty: "file.path.relative.empty";
|
|
9
|
+
};
|
|
10
|
+
export declare const FilePathRelativeSchema: z.core.$ZodBranded<z.ZodPipe<z.ZodString, z.ZodTransform<{
|
|
11
|
+
directory: string & z.core.$brand<"DirectoryPathRelativeSchema">;
|
|
9
12
|
filename: Filename;
|
|
10
|
-
}, string
|
|
13
|
+
}, string>>, "FilePathRelativeSchema">;
|
|
11
14
|
export type FilePathRelativeType = z.infer<typeof FilePathRelativeSchema>;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
2
|
import { DirectoryPathRelativeSchema } from "./directory-path-relative.vo";
|
|
3
3
|
import { Filename } from "./filename.vo";
|
|
4
|
-
export const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
export const FilePathRelativeSchemaError = {
|
|
5
|
+
Type: "file.path.relative.type",
|
|
6
|
+
LeadingSlash: "file.path.relative.leading.slash",
|
|
7
|
+
BackslashForbidden: "file.path.relative.backslash.forbidden",
|
|
8
|
+
RequiresDirectory: "file.path.relative.requires.directory",
|
|
9
|
+
Empty: "file.path.relative.empty",
|
|
10
|
+
};
|
|
8
11
|
export const FilePathRelativeSchema = z
|
|
9
|
-
.string(
|
|
10
|
-
.
|
|
11
|
-
.refine((value) => !value.startsWith("/"),
|
|
12
|
-
.refine((value) => !value.includes("\\"),
|
|
13
|
-
|
|
14
|
-
.transform((value) => value.replace(/\/{2,}/g, "/").replace(/^\/+|\/+$/g, ""))
|
|
15
|
-
.refine((value) => value.includes("/"), RelFilePathRequiresDirectoryError)
|
|
12
|
+
.string(FilePathRelativeSchemaError.Type)
|
|
13
|
+
.min(1, FilePathRelativeSchemaError.Empty)
|
|
14
|
+
.refine((value) => !value.startsWith("/"), FilePathRelativeSchemaError.LeadingSlash)
|
|
15
|
+
.refine((value) => !value.includes("\\"), FilePathRelativeSchemaError.BackslashForbidden)
|
|
16
|
+
.refine((value) => value.includes("/"), FilePathRelativeSchemaError.RequiresDirectory)
|
|
16
17
|
.transform((normalized) => {
|
|
17
18
|
const lastSlashIndex = normalized.lastIndexOf("/");
|
|
18
19
|
const directoryCandidate = normalized.slice(0, lastSlashIndex);
|
|
@@ -20,4 +21,5 @@ export const FilePathRelativeSchema = z
|
|
|
20
21
|
const directory = DirectoryPathRelativeSchema.parse(directoryCandidate);
|
|
21
22
|
const filename = Filename.fromString(filenameCandidate);
|
|
22
23
|
return { directory, filename };
|
|
23
|
-
})
|
|
24
|
+
})
|
|
25
|
+
.brand("FilePathRelativeSchema");
|
package/dist/file-path.vo.d.ts
CHANGED
|
@@ -7,11 +7,11 @@ export declare class FilePathRelative {
|
|
|
7
7
|
private constructor();
|
|
8
8
|
static fromParts(directoryCandidate: string, filename: Filename): FilePathRelative;
|
|
9
9
|
static fromPartsSafe(directory: DirectoryPathRelativeType, filename: Filename): FilePathRelative;
|
|
10
|
-
static fromString(
|
|
10
|
+
static fromString(candidate: string): FilePathRelative;
|
|
11
11
|
get(): string;
|
|
12
12
|
getDirectory(): DirectoryPathRelativeType;
|
|
13
13
|
getFilename(): Filename;
|
|
14
|
-
|
|
14
|
+
withDirectory(newDirectory: DirectoryPathRelativeType): FilePathRelative;
|
|
15
15
|
withFilename(newFilename: Filename): FilePathRelative;
|
|
16
16
|
toAbsolute(newDirectory: DirectoryPathAbsoluteType): FilePathAbsolute;
|
|
17
17
|
}
|
|
@@ -21,11 +21,11 @@ export declare class FilePathAbsolute {
|
|
|
21
21
|
private constructor();
|
|
22
22
|
static fromParts(directoryCandidate: string, filename: Filename): FilePathAbsolute;
|
|
23
23
|
static fromPartsSafe(directory: DirectoryPathAbsoluteType, filename: Filename): FilePathAbsolute;
|
|
24
|
-
static fromString(
|
|
24
|
+
static fromString(candidate: string): FilePathAbsolute;
|
|
25
25
|
get(): string;
|
|
26
26
|
getDirectory(): DirectoryPathAbsoluteType;
|
|
27
27
|
getFilename(): Filename;
|
|
28
|
-
|
|
28
|
+
withDirectory(newDirectory: DirectoryPathAbsoluteType): FilePathAbsolute;
|
|
29
29
|
withFilename(newFilename: Filename): FilePathAbsolute;
|
|
30
30
|
toRelative(newDirectory: DirectoryPathRelativeType): FilePathRelative;
|
|
31
31
|
}
|
package/dist/file-path.vo.js
CHANGED
|
@@ -16,9 +16,9 @@ export class FilePathRelative {
|
|
|
16
16
|
static fromPartsSafe(directory, filename) {
|
|
17
17
|
return new FilePathRelative(directory, filename);
|
|
18
18
|
}
|
|
19
|
-
static fromString(
|
|
20
|
-
const
|
|
21
|
-
return new FilePathRelative(
|
|
19
|
+
static fromString(candidate) {
|
|
20
|
+
const schema = FilePathRelativeSchema.parse(candidate);
|
|
21
|
+
return new FilePathRelative(schema.directory, schema.filename);
|
|
22
22
|
}
|
|
23
23
|
get() {
|
|
24
24
|
return `${this.directory}/${this.filename.get()}`;
|
|
@@ -29,7 +29,7 @@ export class FilePathRelative {
|
|
|
29
29
|
getFilename() {
|
|
30
30
|
return this.filename;
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
withDirectory(newDirectory) {
|
|
33
33
|
return new FilePathRelative(newDirectory, this.filename);
|
|
34
34
|
}
|
|
35
35
|
withFilename(newFilename) {
|
|
@@ -53,9 +53,9 @@ export class FilePathAbsolute {
|
|
|
53
53
|
static fromPartsSafe(directory, filename) {
|
|
54
54
|
return new FilePathAbsolute(directory, filename);
|
|
55
55
|
}
|
|
56
|
-
static fromString(
|
|
57
|
-
const
|
|
58
|
-
return new FilePathAbsolute(
|
|
56
|
+
static fromString(candidate) {
|
|
57
|
+
const schema = FilePathAbsoluteSchema.parse(candidate);
|
|
58
|
+
return new FilePathAbsolute(schema.directory, schema.filename);
|
|
59
59
|
}
|
|
60
60
|
get() {
|
|
61
61
|
if (this.directory === "/")
|
|
@@ -68,7 +68,7 @@ export class FilePathAbsolute {
|
|
|
68
68
|
getFilename() {
|
|
69
69
|
return this.filename;
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
withDirectory(newDirectory) {
|
|
72
72
|
return new FilePathAbsolute(newDirectory, this.filename);
|
|
73
73
|
}
|
|
74
74
|
withFilename(newFilename) {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
2
|
+
export declare const FilenameFromStringError: {
|
|
3
|
+
readonly Type: "filename.from.string.type";
|
|
4
|
+
readonly Invalid: "filename.from.string.Invalid";
|
|
5
|
+
};
|
|
4
6
|
export declare const FilenameFromString: z.ZodPipe<z.ZodString, z.ZodTransform<{
|
|
5
7
|
basename: string & z.core.$brand<"Basename">;
|
|
6
8
|
extension: string & z.core.$brand<"Extension">;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
2
|
import { Basename } from "./basename.vo";
|
|
3
3
|
import { Extension } from "./extension.vo";
|
|
4
|
-
export const
|
|
5
|
-
|
|
4
|
+
export const FilenameFromStringError = {
|
|
5
|
+
Type: "filename.from.string.type",
|
|
6
|
+
Invalid: "filename.from.string.Invalid",
|
|
7
|
+
};
|
|
8
|
+
// .+ at least one character, advances to the last dot
|
|
9
|
+
// .
|
|
10
|
+
// .+ at least one character
|
|
11
|
+
const DOT_WITH_SIDES = /^.+\..+$/;
|
|
6
12
|
export const FilenameFromString = z
|
|
7
|
-
.string(
|
|
8
|
-
.
|
|
9
|
-
.refine((value) => {
|
|
10
|
-
const index = value.lastIndexOf(".");
|
|
11
|
-
return index > 0 && index < value.length - 1;
|
|
12
|
-
}, FilenameInvalidError)
|
|
13
|
+
.string(FilenameFromStringError.Type)
|
|
14
|
+
.regex(DOT_WITH_SIDES, FilenameFromStringError.Invalid)
|
|
13
15
|
.transform((value) => {
|
|
14
16
|
const index = value.lastIndexOf(".");
|
|
15
17
|
const basename = Basename.parse(value.slice(0, index));
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export declare const FilenameSuffixError: {
|
|
3
|
+
readonly Type: "suffix.type";
|
|
4
|
+
readonly Empty: "suffix.empty";
|
|
5
|
+
readonly TooLong: "suffix.too.long";
|
|
6
|
+
readonly BadChars: "suffix.bad.chars";
|
|
7
|
+
};
|
|
8
|
+
export declare const FilenameSuffix: z.core.$ZodBranded<z.ZodString, "FilenameSuffix">;
|
|
5
9
|
export type FilenameSuffixType = z.infer<typeof FilenameSuffix>;
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export const
|
|
3
|
-
|
|
2
|
+
export const FilenameSuffixError = {
|
|
3
|
+
Type: "suffix.type",
|
|
4
|
+
Empty: "suffix.empty",
|
|
5
|
+
TooLong: "suffix.too.long",
|
|
6
|
+
BadChars: "suffix.bad.chars",
|
|
7
|
+
};
|
|
8
|
+
// Letters, digits, underscores, and hyphens allowed
|
|
9
|
+
const FILENAME_SUFFIX_WHITELIST = /^[a-zA-Z0-9_-]+$/;
|
|
4
10
|
export const FilenameSuffix = z
|
|
5
|
-
.string(
|
|
6
|
-
.
|
|
7
|
-
.
|
|
8
|
-
.
|
|
9
|
-
.brand("
|
|
11
|
+
.string(FilenameSuffixError.Type)
|
|
12
|
+
.min(1, FilenameSuffixError.Empty)
|
|
13
|
+
.max(32, FilenameSuffixError.TooLong)
|
|
14
|
+
.regex(FILENAME_SUFFIX_WHITELIST, FilenameSuffixError.BadChars)
|
|
15
|
+
.brand("FilenameSuffix");
|
package/dist/filename.vo.d.ts
CHANGED
package/dist/filename.vo.js
CHANGED
|
@@ -16,8 +16,8 @@ export class Filename {
|
|
|
16
16
|
return new Filename(basename, extension);
|
|
17
17
|
}
|
|
18
18
|
static fromString(candidate) {
|
|
19
|
-
const
|
|
20
|
-
return new Filename(basename, extension);
|
|
19
|
+
const filename = FilenameFromString.parse(candidate);
|
|
20
|
+
return new Filename(filename.basename, filename.extension);
|
|
21
21
|
}
|
|
22
22
|
get() {
|
|
23
23
|
return `${this.basename}.${this.extension}`;
|
|
@@ -43,4 +43,10 @@ export class Filename {
|
|
|
43
43
|
const basename = Basename.parse(`${this.basename}${suffix}`);
|
|
44
44
|
return new Filename(basename, this.extension);
|
|
45
45
|
}
|
|
46
|
+
toString() {
|
|
47
|
+
return this.get();
|
|
48
|
+
}
|
|
49
|
+
toJSON() {
|
|
50
|
+
return this.get();
|
|
51
|
+
}
|
|
46
52
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export declare const HeightMillimetersError: {
|
|
3
|
+
readonly Type: "height.millimeters.type";
|
|
4
|
+
readonly Invalid: "height.millimeters.invalid";
|
|
5
|
+
};
|
|
6
|
+
export declare const HeightMillimeters: z.core.$ZodBranded<z.ZodNumber, "HeightMillimeters">;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export const HeightMillimetersError = {
|
|
3
|
+
Type: "height.millimeters.type",
|
|
4
|
+
Invalid: "height.millimeters.invalid",
|
|
5
|
+
};
|
|
6
|
+
export const HeightMillimeters = z
|
|
7
|
+
.number(HeightMillimetersError.Type)
|
|
8
|
+
.int(HeightMillimetersError.Type)
|
|
9
|
+
.min(0, HeightMillimetersError.Invalid)
|
|
10
|
+
.brand("HeightMillimeters");
|