@bgord/tools 0.12.16 → 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/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.subtype);
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/tools",
3
- "version": "0.12.16",
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.20",
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.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.1"
42
+ "zod": "4.1.3"
41
43
  },
42
44
  "sideEffects": false
43
45
  }
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.subtype);
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
  }