@bgord/tools 0.12.15 → 0.12.17
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/file-path-absolute-schema.vo.d.ts +6 -0
- package/dist/file-path-absolute-schema.vo.js +19 -0
- package/dist/file-path-relative-schema.vo.d.ts +6 -0
- package/dist/file-path-relative-schema.vo.js +19 -0
- package/dist/file-path.vo.d.ts +2 -0
- package/dist/file-path.vo.js +10 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/mime.vo.d.ts +1 -0
- package/dist/mime.vo.js +5 -1
- package/dist/size.vo.d.ts +4 -0
- package/dist/size.vo.js +16 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -5
- package/readme.md +2 -0
- package/src/file-path-absolute-schema.vo.ts +22 -0
- package/src/file-path-relative-schema.vo.ts +22 -0
- package/src/file-path.vo.ts +12 -0
- package/src/index.ts +2 -0
- package/src/mime.vo.ts +6 -1
- package/src/size.vo.ts +20 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import { Filename } from "./filename.vo";
|
|
3
|
+
export declare const FilePathAbsoluteSchema: z.ZodPipe<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<string, string>>, z.ZodTransform<{
|
|
4
|
+
directory: string & z.core.$brand<"absolute_directory_path">;
|
|
5
|
+
filename: Filename;
|
|
6
|
+
}, string>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import { DirectoryPathAbsoluteSchema } from "./directory-path-absolute.vo";
|
|
3
|
+
import { Filename } from "./filename.vo";
|
|
4
|
+
export const FilePathAbsoluteSchema = z
|
|
5
|
+
.string()
|
|
6
|
+
.trim()
|
|
7
|
+
.refine((value) => value.startsWith("/"), "abs_file_path_must_start_with_slash")
|
|
8
|
+
.refine((value) => !value.includes("\\"), "abs_file_path_backslash_forbidden")
|
|
9
|
+
.transform((value) => value.replace(/\/{2,}/g, "/")) // collapse //
|
|
10
|
+
.transform((value) => (value !== "/" && value.endsWith("/") ? value.slice(0, -1) : value)) // keep "/" as-is
|
|
11
|
+
.refine((value) => value !== "/", "abs_file_path_missing_filename")
|
|
12
|
+
.transform((normalized) => {
|
|
13
|
+
const lastSlashIndex = normalized.lastIndexOf("/");
|
|
14
|
+
const directoryCandidate = lastSlashIndex === 0 ? "/" : normalized.slice(0, lastSlashIndex);
|
|
15
|
+
const filenameCandidate = normalized.slice(lastSlashIndex + 1);
|
|
16
|
+
const directory = DirectoryPathAbsoluteSchema.parse(directoryCandidate);
|
|
17
|
+
const filename = Filename.fromString(filenameCandidate);
|
|
18
|
+
return { directory, filename };
|
|
19
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import { Filename } from "./filename.vo";
|
|
3
|
+
export declare const FilePathRelativeSchema: z.ZodPipe<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<string, string>>, z.ZodTransform<{
|
|
4
|
+
directory: string & z.core.$brand<"relative_directory_path">;
|
|
5
|
+
filename: Filename;
|
|
6
|
+
}, string>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import { DirectoryPathRelativeSchema } from "./directory-path-relative.vo";
|
|
3
|
+
import { Filename } from "./filename.vo";
|
|
4
|
+
export const FilePathRelativeSchema = z
|
|
5
|
+
.string()
|
|
6
|
+
.trim()
|
|
7
|
+
.refine((value) => !value.startsWith("/"), "rel_file_path_must_not_start_with_slash")
|
|
8
|
+
.refine((value) => !value.includes("\\"), "rel_file_path_backslash_forbidden")
|
|
9
|
+
.transform((value) => value.replace(/\/{2,}/g, "/")) // collapse //
|
|
10
|
+
.transform((value) => value.replace(/^\/+|\/+$/g, "")) // trim leading/trailing slashes
|
|
11
|
+
.refine((value) => value.includes("/"), "rel_file_path_requires_directory")
|
|
12
|
+
.transform((normalized) => {
|
|
13
|
+
const lastSlashIndex = normalized.lastIndexOf("/");
|
|
14
|
+
const directoryCandidate = normalized.slice(0, lastSlashIndex);
|
|
15
|
+
const filenameCandidate = normalized.slice(lastSlashIndex + 1);
|
|
16
|
+
const directory = DirectoryPathRelativeSchema.parse(directoryCandidate);
|
|
17
|
+
const filename = Filename.fromString(filenameCandidate);
|
|
18
|
+
return { directory, filename };
|
|
19
|
+
});
|
package/dist/file-path.vo.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ 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(pathCandidate: string): FilePathRelative;
|
|
10
11
|
get(): string;
|
|
11
12
|
getDirectory(): DirectoryPathRelativeType;
|
|
12
13
|
getFilename(): Filename;
|
|
@@ -20,6 +21,7 @@ export declare class FilePathAbsolute {
|
|
|
20
21
|
private constructor();
|
|
21
22
|
static fromParts(directoryCandidate: string, filename: Filename): FilePathAbsolute;
|
|
22
23
|
static fromPartsSafe(directory: DirectoryPathAbsoluteType, filename: Filename): FilePathAbsolute;
|
|
24
|
+
static fromString(pathCandidate: string): FilePathAbsolute;
|
|
23
25
|
get(): string;
|
|
24
26
|
getDirectory(): DirectoryPathAbsoluteType;
|
|
25
27
|
getFilename(): Filename;
|
package/dist/file-path.vo.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { DirectoryPathAbsoluteSchema } from "./directory-path-absolute.vo";
|
|
2
2
|
import { DirectoryPathRelativeSchema } from "./directory-path-relative.vo";
|
|
3
|
+
import { FilePathAbsoluteSchema } from "./file-path-absolute-schema.vo";
|
|
4
|
+
import { FilePathRelativeSchema } from "./file-path-relative-schema.vo";
|
|
3
5
|
export class FilePathRelative {
|
|
4
6
|
directory;
|
|
5
7
|
filename;
|
|
@@ -14,6 +16,10 @@ export class FilePathRelative {
|
|
|
14
16
|
static fromPartsSafe(directory, filename) {
|
|
15
17
|
return new FilePathRelative(directory, filename);
|
|
16
18
|
}
|
|
19
|
+
static fromString(pathCandidate) {
|
|
20
|
+
const { directory, filename } = FilePathRelativeSchema.parse(pathCandidate);
|
|
21
|
+
return new FilePathRelative(directory, filename);
|
|
22
|
+
}
|
|
17
23
|
get() {
|
|
18
24
|
return `${this.directory}/${this.filename.get()}`;
|
|
19
25
|
}
|
|
@@ -47,6 +53,10 @@ export class FilePathAbsolute {
|
|
|
47
53
|
static fromPartsSafe(directory, filename) {
|
|
48
54
|
return new FilePathAbsolute(directory, filename);
|
|
49
55
|
}
|
|
56
|
+
static fromString(pathCandidate) {
|
|
57
|
+
const { directory, filename } = FilePathAbsoluteSchema.parse(pathCandidate);
|
|
58
|
+
return new FilePathAbsolute(directory, filename);
|
|
59
|
+
}
|
|
50
60
|
get() {
|
|
51
61
|
if (this.directory === "/")
|
|
52
62
|
return `/${this.filename.get()}`;
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export * from "./etags.vo";
|
|
|
16
16
|
export * from "./extension.vo";
|
|
17
17
|
export * from "./feature-flag.vo";
|
|
18
18
|
export * from "./file-path.vo";
|
|
19
|
+
export * from "./file-path-absolute-schema.vo";
|
|
20
|
+
export * from "./file-path-relative-schema.vo";
|
|
19
21
|
export * from "./filename.vo";
|
|
20
22
|
export * from "./filename-from-string.vo";
|
|
21
23
|
export * from "./filename-suffix.vo";
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,8 @@ export * from "./etags.vo";
|
|
|
16
16
|
export * from "./extension.vo";
|
|
17
17
|
export * from "./feature-flag.vo";
|
|
18
18
|
export * from "./file-path.vo";
|
|
19
|
+
export * from "./file-path-absolute-schema.vo";
|
|
20
|
+
export * from "./file-path-relative-schema.vo";
|
|
19
21
|
export * from "./filename.vo";
|
|
20
22
|
export * from "./filename-from-string.vo";
|
|
21
23
|
export * from "./filename-suffix.vo";
|
package/dist/mime.vo.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare class Mime {
|
|
|
7
7
|
readonly type: MimeTypeType;
|
|
8
8
|
readonly subtype: MimeSubtypeType;
|
|
9
9
|
constructor(value: MimeRawType);
|
|
10
|
+
static fromExtension(extension: ExtensionType): Mime;
|
|
10
11
|
isSatisfiedBy(another: Mime): boolean;
|
|
11
12
|
toExtension(): ExtensionType;
|
|
12
13
|
}
|
package/dist/mime.vo.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as mime from "mime-types";
|
|
1
2
|
import { ExtensionSchema } from "./extension.vo";
|
|
2
3
|
export class Mime {
|
|
3
4
|
raw;
|
|
@@ -15,6 +16,9 @@ export class Mime {
|
|
|
15
16
|
this.type = type;
|
|
16
17
|
this.subtype = subtype;
|
|
17
18
|
}
|
|
19
|
+
static fromExtension(extension) {
|
|
20
|
+
return new Mime(String(mime.contentType(extension)));
|
|
21
|
+
}
|
|
18
22
|
isSatisfiedBy(another) {
|
|
19
23
|
if (this.raw === another.raw)
|
|
20
24
|
return true;
|
|
@@ -24,7 +28,7 @@ export class Mime {
|
|
|
24
28
|
return this.subtype === another.subtype || this.subtype === "*";
|
|
25
29
|
}
|
|
26
30
|
toExtension() {
|
|
27
|
-
return ExtensionSchema.parse(this.
|
|
31
|
+
return ExtensionSchema.parse(mime.extension(this.raw));
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
34
|
export class InvalidMimeError extends Error {
|
package/dist/size.vo.d.ts
CHANGED
|
@@ -19,6 +19,10 @@ export declare class Size {
|
|
|
19
19
|
private static readonly MB_MULTIPLIER;
|
|
20
20
|
private static readonly GB_MULTIPLIER;
|
|
21
21
|
constructor(config: SizeConfigType);
|
|
22
|
+
static fromBytes(candidate: number): Size;
|
|
23
|
+
static fromKb(candidate: number): Size;
|
|
24
|
+
static fromMB(candidate: number): Size;
|
|
25
|
+
static fromGB(candidate: number): Size;
|
|
22
26
|
toString(): string;
|
|
23
27
|
toBytes(): SizeValueType;
|
|
24
28
|
isGreaterThan(another: Size): boolean;
|
package/dist/size.vo.js
CHANGED
|
@@ -20,6 +20,22 @@ export class Size {
|
|
|
20
20
|
this.value = SizeValue.parse(config.value);
|
|
21
21
|
this.bytes = this.calculateBytes();
|
|
22
22
|
}
|
|
23
|
+
static fromBytes(candidate) {
|
|
24
|
+
const value = SizeValue.parse(candidate);
|
|
25
|
+
return new Size({ value, unit: SizeUnit.b });
|
|
26
|
+
}
|
|
27
|
+
static fromKb(candidate) {
|
|
28
|
+
const value = SizeValue.parse(candidate);
|
|
29
|
+
return new Size({ value, unit: SizeUnit.kB });
|
|
30
|
+
}
|
|
31
|
+
static fromMB(candidate) {
|
|
32
|
+
const value = SizeValue.parse(candidate);
|
|
33
|
+
return new Size({ value, unit: SizeUnit.MB });
|
|
34
|
+
}
|
|
35
|
+
static fromGB(candidate) {
|
|
36
|
+
const value = SizeValue.parse(candidate);
|
|
37
|
+
return new Size({ value, unit: SizeUnit.GB });
|
|
38
|
+
}
|
|
23
39
|
toString() {
|
|
24
40
|
return `${this.value} ${this.unit}`;
|
|
25
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/api-key.vo.ts","../src/basename.vo.ts","../src/build-version.vo.ts","../src/clock.vo.ts","../src/date-calculator.service.ts","../src/date-formatter.service.ts","../src/date-range.vo.ts","../src/dates-of-the-week.vo.ts","../src/day-iso-id.vo.ts","../src/day.vo.ts","../src/directory-path-absolute.vo.ts","../src/directory-path-relative.vo.ts","../src/dll.service.ts","../src/email-mask.service.ts","../src/etags.vo.ts","../src/extension.vo.ts","../src/feature-flag.vo.ts","../src/file-path.vo.ts","../src/filename-from-string.vo.ts","../src/filename-suffix.vo.ts","../src/filename.vo.ts","../src/filter.vo.ts","../src/hour.vo.ts","../src/iban-mask.service.ts","../src/iban.vo.ts","../src/image.vo.ts","../src/index.ts","../src/language.vo.ts","../src/leap-year-checker.service.ts","../src/mean.service.ts","../src/mime-types.vo.ts","../src/mime.vo.ts","../src/min-max-scaler.service.ts","../src/minute.vo.ts","../src/money.vo.ts","../src/noop.service.ts","../src/notification-template.vo.ts","../src/outlier-detector.service.ts","../src/package-version.vo.ts","../src/pagination.service.ts","../src/percentage.service.ts","../src/population-standard-deviation.service.ts","../src/random.service.ts","../src/rate-limiter.service.ts","../src/relative-date.vo.ts","../src/reordering.service.ts","../src/revision.vo.ts","../src/rounding.service.ts","../src/simple-linear-regression.service.ts","../src/size.vo.ts","../src/stepper.service.ts","../src/stopwatch.service.ts","../src/streak-calculator.service.ts","../src/sum.service.ts","../src/thousands-separator.service.ts","../src/time-zone-offset-value.vo.ts","../src/time.service.ts","../src/timestamp.vo.ts","../src/timezone.vo.ts","../src/ts-utils.ts","../src/visually-unambiguous-characters-generator.service.ts","../src/week-iso-id.vo.ts","../src/week.vo.ts","../src/z-score.service.ts"],"version":"5.9.2"}
|
|
1
|
+
{"root":["../src/api-key.vo.ts","../src/basename.vo.ts","../src/build-version.vo.ts","../src/clock.vo.ts","../src/date-calculator.service.ts","../src/date-formatter.service.ts","../src/date-range.vo.ts","../src/dates-of-the-week.vo.ts","../src/day-iso-id.vo.ts","../src/day.vo.ts","../src/directory-path-absolute.vo.ts","../src/directory-path-relative.vo.ts","../src/dll.service.ts","../src/email-mask.service.ts","../src/etags.vo.ts","../src/extension.vo.ts","../src/feature-flag.vo.ts","../src/file-path-absolute-schema.vo.ts","../src/file-path-relative-schema.vo.ts","../src/file-path.vo.ts","../src/filename-from-string.vo.ts","../src/filename-suffix.vo.ts","../src/filename.vo.ts","../src/filter.vo.ts","../src/hour.vo.ts","../src/iban-mask.service.ts","../src/iban.vo.ts","../src/image.vo.ts","../src/index.ts","../src/language.vo.ts","../src/leap-year-checker.service.ts","../src/mean.service.ts","../src/mime-types.vo.ts","../src/mime.vo.ts","../src/min-max-scaler.service.ts","../src/minute.vo.ts","../src/money.vo.ts","../src/noop.service.ts","../src/notification-template.vo.ts","../src/outlier-detector.service.ts","../src/package-version.vo.ts","../src/pagination.service.ts","../src/percentage.service.ts","../src/population-standard-deviation.service.ts","../src/random.service.ts","../src/rate-limiter.service.ts","../src/relative-date.vo.ts","../src/reordering.service.ts","../src/revision.vo.ts","../src/rounding.service.ts","../src/simple-linear-regression.service.ts","../src/size.vo.ts","../src/stepper.service.ts","../src/stopwatch.service.ts","../src/streak-calculator.service.ts","../src/sum.service.ts","../src/thousands-separator.service.ts","../src/time-zone-offset-value.vo.ts","../src/time.service.ts","../src/timestamp.vo.ts","../src/timezone.vo.ts","../src/ts-utils.ts","../src/visually-unambiguous-characters-generator.service.ts","../src/week-iso-id.vo.ts","../src/week.vo.ts","../src/z-score.service.ts"],"version":"5.9.2"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bgord/tools",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Bartosz Gordon",
|
|
@@ -24,20 +24,22 @@
|
|
|
24
24
|
"@biomejs/biome": "2.2.2",
|
|
25
25
|
"@commitlint/cli": "19.8.1",
|
|
26
26
|
"@commitlint/config-conventional": "19.8.1",
|
|
27
|
-
"@types/bun": "1.2.
|
|
27
|
+
"@types/bun": "1.2.21",
|
|
28
|
+
"@types/mime-types": "^3.0.1",
|
|
28
29
|
"cspell": "9.2.0",
|
|
29
30
|
"knip": "5.63.0",
|
|
30
31
|
"lefthook": "1.12.3",
|
|
31
32
|
"only-allow": "1.2.1",
|
|
32
33
|
"shellcheck": "4.1.0",
|
|
33
34
|
"typescript": "5.9.2",
|
|
34
|
-
"zod": "4.1.
|
|
35
|
+
"zod": "4.1.3"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"date-fns": "4.1.0"
|
|
38
|
+
"date-fns": "4.1.0",
|
|
39
|
+
"mime-types": "^3.0.1"
|
|
38
40
|
},
|
|
39
41
|
"peerDependencies": {
|
|
40
|
-
"zod": "4.1.
|
|
42
|
+
"zod": "4.1.3"
|
|
41
43
|
},
|
|
42
44
|
"sideEffects": false
|
|
43
45
|
}
|
package/readme.md
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import { DirectoryPathAbsoluteSchema } from "./directory-path-absolute.vo";
|
|
3
|
+
import { Filename } from "./filename.vo";
|
|
4
|
+
|
|
5
|
+
export const FilePathAbsoluteSchema = z
|
|
6
|
+
.string()
|
|
7
|
+
.trim()
|
|
8
|
+
.refine((value) => value.startsWith("/"), "abs_file_path_must_start_with_slash")
|
|
9
|
+
.refine((value) => !value.includes("\\"), "abs_file_path_backslash_forbidden")
|
|
10
|
+
.transform((value) => value.replace(/\/{2,}/g, "/")) // collapse //
|
|
11
|
+
.transform((value) => (value !== "/" && value.endsWith("/") ? value.slice(0, -1) : value)) // keep "/" as-is
|
|
12
|
+
.refine((value) => value !== "/", "abs_file_path_missing_filename")
|
|
13
|
+
.transform((normalized) => {
|
|
14
|
+
const lastSlashIndex = normalized.lastIndexOf("/");
|
|
15
|
+
const directoryCandidate = lastSlashIndex === 0 ? "/" : normalized.slice(0, lastSlashIndex);
|
|
16
|
+
const filenameCandidate = normalized.slice(lastSlashIndex + 1);
|
|
17
|
+
|
|
18
|
+
const directory = DirectoryPathAbsoluteSchema.parse(directoryCandidate);
|
|
19
|
+
const filename = Filename.fromString(filenameCandidate);
|
|
20
|
+
|
|
21
|
+
return { directory, filename };
|
|
22
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import { DirectoryPathRelativeSchema } from "./directory-path-relative.vo";
|
|
3
|
+
import { Filename } from "./filename.vo";
|
|
4
|
+
|
|
5
|
+
export const FilePathRelativeSchema = z
|
|
6
|
+
.string()
|
|
7
|
+
.trim()
|
|
8
|
+
.refine((value) => !value.startsWith("/"), "rel_file_path_must_not_start_with_slash")
|
|
9
|
+
.refine((value) => !value.includes("\\"), "rel_file_path_backslash_forbidden")
|
|
10
|
+
.transform((value) => value.replace(/\/{2,}/g, "/")) // collapse //
|
|
11
|
+
.transform((value) => value.replace(/^\/+|\/+$/g, "")) // trim leading/trailing slashes
|
|
12
|
+
.refine((value) => value.includes("/"), "rel_file_path_requires_directory")
|
|
13
|
+
.transform((normalized) => {
|
|
14
|
+
const lastSlashIndex = normalized.lastIndexOf("/");
|
|
15
|
+
const directoryCandidate = normalized.slice(0, lastSlashIndex);
|
|
16
|
+
const filenameCandidate = normalized.slice(lastSlashIndex + 1);
|
|
17
|
+
|
|
18
|
+
const directory = DirectoryPathRelativeSchema.parse(directoryCandidate);
|
|
19
|
+
const filename = Filename.fromString(filenameCandidate);
|
|
20
|
+
|
|
21
|
+
return { directory, filename };
|
|
22
|
+
});
|
package/src/file-path.vo.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { DirectoryPathAbsoluteSchema, type DirectoryPathAbsoluteType } from "./directory-path-absolute.vo";
|
|
2
2
|
import { DirectoryPathRelativeSchema, type DirectoryPathRelativeType } from "./directory-path-relative.vo";
|
|
3
|
+
import { FilePathAbsoluteSchema } from "./file-path-absolute-schema.vo";
|
|
4
|
+
import { FilePathRelativeSchema } from "./file-path-relative-schema.vo";
|
|
3
5
|
import type { Filename } from "./filename.vo";
|
|
4
6
|
|
|
5
7
|
export class FilePathRelative {
|
|
@@ -17,6 +19,11 @@ export class FilePathRelative {
|
|
|
17
19
|
return new FilePathRelative(directory, filename);
|
|
18
20
|
}
|
|
19
21
|
|
|
22
|
+
static fromString(pathCandidate: string): FilePathRelative {
|
|
23
|
+
const { directory, filename } = FilePathRelativeSchema.parse(pathCandidate);
|
|
24
|
+
return new FilePathRelative(directory, filename);
|
|
25
|
+
}
|
|
26
|
+
|
|
20
27
|
get() {
|
|
21
28
|
return `${this.directory}/${this.filename.get()}`;
|
|
22
29
|
}
|
|
@@ -57,6 +64,11 @@ export class FilePathAbsolute {
|
|
|
57
64
|
return new FilePathAbsolute(directory, filename);
|
|
58
65
|
}
|
|
59
66
|
|
|
67
|
+
static fromString(pathCandidate: string): FilePathAbsolute {
|
|
68
|
+
const { directory, filename } = FilePathAbsoluteSchema.parse(pathCandidate);
|
|
69
|
+
return new FilePathAbsolute(directory, filename);
|
|
70
|
+
}
|
|
71
|
+
|
|
60
72
|
get() {
|
|
61
73
|
if (this.directory === ("/" as DirectoryPathAbsoluteType)) return `/${this.filename.get()}`;
|
|
62
74
|
return `${this.directory}/${this.filename.get()}`;
|
package/src/index.ts
CHANGED
|
@@ -16,6 +16,8 @@ export * from "./etags.vo";
|
|
|
16
16
|
export * from "./extension.vo";
|
|
17
17
|
export * from "./feature-flag.vo";
|
|
18
18
|
export * from "./file-path.vo";
|
|
19
|
+
export * from "./file-path-absolute-schema.vo";
|
|
20
|
+
export * from "./file-path-relative-schema.vo";
|
|
19
21
|
export * from "./filename.vo";
|
|
20
22
|
export * from "./filename-from-string.vo";
|
|
21
23
|
export * from "./filename-suffix.vo";
|
package/src/mime.vo.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as mime from "mime-types";
|
|
1
2
|
import { ExtensionSchema, type ExtensionType } from "./extension.vo";
|
|
2
3
|
|
|
3
4
|
export type MimeRawType = string;
|
|
@@ -27,6 +28,10 @@ export class Mime {
|
|
|
27
28
|
this.subtype = subtype;
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
static fromExtension(extension: ExtensionType): Mime {
|
|
32
|
+
return new Mime(String(mime.contentType(extension)));
|
|
33
|
+
}
|
|
34
|
+
|
|
30
35
|
isSatisfiedBy(another: Mime): boolean {
|
|
31
36
|
if (this.raw === another.raw) return true;
|
|
32
37
|
|
|
@@ -37,7 +42,7 @@ export class Mime {
|
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
toExtension(): ExtensionType {
|
|
40
|
-
return ExtensionSchema.parse(this.
|
|
45
|
+
return ExtensionSchema.parse(mime.extension(this.raw));
|
|
41
46
|
}
|
|
42
47
|
}
|
|
43
48
|
|
package/src/size.vo.ts
CHANGED
|
@@ -33,6 +33,26 @@ export class Size {
|
|
|
33
33
|
this.bytes = this.calculateBytes();
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
static fromBytes(candidate: number): Size {
|
|
37
|
+
const value = SizeValue.parse(candidate);
|
|
38
|
+
return new Size({ value, unit: SizeUnit.b });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static fromKb(candidate: number): Size {
|
|
42
|
+
const value = SizeValue.parse(candidate);
|
|
43
|
+
return new Size({ value, unit: SizeUnit.kB });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static fromMB(candidate: number): Size {
|
|
47
|
+
const value = SizeValue.parse(candidate);
|
|
48
|
+
return new Size({ value, unit: SizeUnit.MB });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static fromGB(candidate: number): Size {
|
|
52
|
+
const value = SizeValue.parse(candidate);
|
|
53
|
+
return new Size({ value, unit: SizeUnit.GB });
|
|
54
|
+
}
|
|
55
|
+
|
|
36
56
|
toString(): string {
|
|
37
57
|
return `${this.value} ${this.unit}`;
|
|
38
58
|
}
|