@bgord/tools 1.0.2 → 1.0.4

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.
@@ -6,12 +6,15 @@ export declare class Duration {
6
6
  private static readonly MS_IN_MINUTE;
7
7
  private static readonly MS_IN_HOUR;
8
8
  private static readonly MS_IN_DAY;
9
+ private static readonly MS_IN_WEEK;
9
10
  private constructor();
11
+ static Weeks(value: number): Duration;
10
12
  static Days(value: number): Duration;
11
13
  static Hours(value: number): Duration;
12
14
  static Minutes(value: number): Duration;
13
15
  static Seconds(value: number): Duration;
14
16
  static Ms(value: number): Duration;
17
+ get weeks(): number;
15
18
  get days(): number;
16
19
  get hours(): number;
17
20
  get minutes(): number;
@@ -7,9 +7,13 @@ export class Duration {
7
7
  static MS_IN_MINUTE = 60 * Duration.MS_IN_SECOND;
8
8
  static MS_IN_HOUR = 60 * Duration.MS_IN_MINUTE;
9
9
  static MS_IN_DAY = 24 * Duration.MS_IN_HOUR;
10
+ static MS_IN_WEEK = 7 * Duration.MS_IN_DAY;
10
11
  constructor(candidateMs) {
11
12
  this.internal = DurationMs.parse(candidateMs);
12
13
  }
14
+ static Weeks(value) {
15
+ return new Duration(value * Duration.MS_IN_WEEK);
16
+ }
13
17
  static Days(value) {
14
18
  return new Duration(value * Duration.MS_IN_DAY);
15
19
  }
@@ -25,6 +29,9 @@ export class Duration {
25
29
  static Ms(value) {
26
30
  return new Duration(value);
27
31
  }
32
+ get weeks() {
33
+ return Duration.rounding.round(this.internal / Duration.MS_IN_WEEK);
34
+ }
28
35
  get days() {
29
36
  return Duration.rounding.round(this.internal / Duration.MS_IN_DAY);
30
37
  }
package/dist/size.vo.d.ts CHANGED
@@ -15,13 +15,17 @@ export declare class Size {
15
15
  private static readonly KB_MULTIPLIER;
16
16
  private static readonly MB_MULTIPLIER;
17
17
  private static readonly GB_MULTIPLIER;
18
- private static readonly ROUNDER;
18
+ private static readonly CONVERT_ROUND;
19
+ private static readonly FORMAT_ROUND;
19
20
  constructor(config: SizeConfigType);
20
21
  static fromBytes(value: SizeConfigType["value"]): Size;
21
22
  static fromKb(value: SizeConfigType["value"]): Size;
22
23
  static fromMB(value: SizeConfigType["value"]): Size;
23
24
  static fromGB(value: SizeConfigType["value"]): Size;
24
25
  toBytes(): SizeBytesType;
26
+ tokB(): number;
27
+ toMB(): number;
28
+ toGB(): number;
25
29
  isGreaterThan(another: Size): boolean;
26
30
  format(unit: SizeUnitEnum): string;
27
31
  static toBytes(config: SizeConfigType): SizeBytesType;
package/dist/size.vo.js CHANGED
@@ -1,4 +1,4 @@
1
- import { RoundToDecimal } from "./rounding.adapter";
1
+ import { RoundToDecimal, RoundUp } from "./rounding.adapter";
2
2
  import { SizeBytes } from "./size-bytes.vo";
3
3
  var SizeUnitEnum;
4
4
  (function (SizeUnitEnum) {
@@ -13,7 +13,8 @@ export class Size {
13
13
  static KB_MULTIPLIER = 1024;
14
14
  static MB_MULTIPLIER = 1024 * Size.KB_MULTIPLIER;
15
15
  static GB_MULTIPLIER = 1024 * Size.MB_MULTIPLIER;
16
- static ROUNDER = new RoundToDecimal(2);
16
+ static CONVERT_ROUND = new RoundUp();
17
+ static FORMAT_ROUND = new RoundToDecimal(2);
17
18
  constructor(config) {
18
19
  this.unit = config.unit;
19
20
  this.bytes = this.calculateBytes(config.value, config.unit);
@@ -33,17 +34,26 @@ export class Size {
33
34
  toBytes() {
34
35
  return this.bytes;
35
36
  }
37
+ tokB() {
38
+ return Size.CONVERT_ROUND.round(this.bytes / Size.KB_MULTIPLIER);
39
+ }
40
+ toMB() {
41
+ return Size.CONVERT_ROUND.round(this.bytes / Size.MB_MULTIPLIER);
42
+ }
43
+ toGB() {
44
+ return Size.CONVERT_ROUND.round(this.bytes / Size.GB_MULTIPLIER);
45
+ }
36
46
  isGreaterThan(another) {
37
47
  return this.bytes > another.toBytes();
38
48
  }
39
49
  format(unit) {
40
50
  switch (unit) {
41
51
  case SizeUnitEnum.kB:
42
- return `${Size.ROUNDER.round(this.bytes / Size.KB_MULTIPLIER)} ${SizeUnitEnum.kB}`;
52
+ return `${Size.FORMAT_ROUND.round(this.bytes / Size.KB_MULTIPLIER)} ${SizeUnitEnum.kB}`;
43
53
  case SizeUnitEnum.MB:
44
- return `${Size.ROUNDER.round(this.bytes / Size.MB_MULTIPLIER)} ${SizeUnitEnum.MB}`;
54
+ return `${Size.FORMAT_ROUND.round(this.bytes / Size.MB_MULTIPLIER)} ${SizeUnitEnum.MB}`;
45
55
  case SizeUnitEnum.GB:
46
- return `${Size.ROUNDER.round(this.bytes / Size.GB_MULTIPLIER)} ${SizeUnitEnum.GB}`;
56
+ return `${Size.FORMAT_ROUND.round(this.bytes / Size.GB_MULTIPLIER)} ${SizeUnitEnum.GB}`;
47
57
  default:
48
58
  return `${this.bytes} ${SizeUnitEnum.b}`;
49
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/tools",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Bartosz Gordon",
@@ -21,7 +21,7 @@
21
21
  "preinstall": "bunx only-allow bun"
22
22
  },
23
23
  "devDependencies": {
24
- "@biomejs/biome": "2.3.0",
24
+ "@biomejs/biome": "2.3.1",
25
25
  "@commitlint/cli": "20.1.0",
26
26
  "@commitlint/config-conventional": "20.0.0",
27
27
  "@types/bun": "1.3.1",
@@ -10,11 +10,16 @@ export class Duration {
10
10
  private static readonly MS_IN_MINUTE = 60 * Duration.MS_IN_SECOND;
11
11
  private static readonly MS_IN_HOUR = 60 * Duration.MS_IN_MINUTE;
12
12
  private static readonly MS_IN_DAY = 24 * Duration.MS_IN_HOUR;
13
+ private static readonly MS_IN_WEEK = 7 * Duration.MS_IN_DAY;
13
14
 
14
15
  private constructor(candidateMs: number) {
15
16
  this.internal = DurationMs.parse(candidateMs);
16
17
  }
17
18
 
19
+ static Weeks(value: number): Duration {
20
+ return new Duration(value * Duration.MS_IN_WEEK);
21
+ }
22
+
18
23
  static Days(value: number): Duration {
19
24
  return new Duration(value * Duration.MS_IN_DAY);
20
25
  }
@@ -31,6 +36,10 @@ export class Duration {
31
36
  return new Duration(value);
32
37
  }
33
38
 
39
+ get weeks(): number {
40
+ return Duration.rounding.round(this.internal / Duration.MS_IN_WEEK);
41
+ }
42
+
34
43
  get days(): number {
35
44
  return Duration.rounding.round(this.internal / Duration.MS_IN_DAY);
36
45
  }
package/src/size.vo.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { RoundToDecimal } from "./rounding.adapter";
1
+ import { RoundToDecimal, RoundUp } from "./rounding.adapter";
2
2
  import { SizeBytes, type SizeBytesType } from "./size-bytes.vo";
3
3
 
4
4
  enum SizeUnitEnum {
@@ -18,7 +18,8 @@ export class Size {
18
18
  private static readonly MB_MULTIPLIER = 1024 * Size.KB_MULTIPLIER;
19
19
  private static readonly GB_MULTIPLIER = 1024 * Size.MB_MULTIPLIER;
20
20
 
21
- private static readonly ROUNDER = new RoundToDecimal(2);
21
+ private static readonly CONVERT_ROUND = new RoundUp();
22
+ private static readonly FORMAT_ROUND = new RoundToDecimal(2);
22
23
 
23
24
  constructor(config: SizeConfigType) {
24
25
  this.unit = config.unit;
@@ -45,6 +46,18 @@ export class Size {
45
46
  return this.bytes;
46
47
  }
47
48
 
49
+ tokB(): number {
50
+ return Size.CONVERT_ROUND.round(this.bytes / Size.KB_MULTIPLIER);
51
+ }
52
+
53
+ toMB(): number {
54
+ return Size.CONVERT_ROUND.round(this.bytes / Size.MB_MULTIPLIER);
55
+ }
56
+
57
+ toGB(): number {
58
+ return Size.CONVERT_ROUND.round(this.bytes / Size.GB_MULTIPLIER);
59
+ }
60
+
48
61
  isGreaterThan(another: Size): boolean {
49
62
  return this.bytes > another.toBytes();
50
63
  }
@@ -52,11 +65,11 @@ export class Size {
52
65
  format(unit: SizeUnitEnum): string {
53
66
  switch (unit) {
54
67
  case SizeUnitEnum.kB:
55
- return `${Size.ROUNDER.round(this.bytes / Size.KB_MULTIPLIER)} ${SizeUnitEnum.kB}`;
68
+ return `${Size.FORMAT_ROUND.round(this.bytes / Size.KB_MULTIPLIER)} ${SizeUnitEnum.kB}`;
56
69
  case SizeUnitEnum.MB:
57
- return `${Size.ROUNDER.round(this.bytes / Size.MB_MULTIPLIER)} ${SizeUnitEnum.MB}`;
70
+ return `${Size.FORMAT_ROUND.round(this.bytes / Size.MB_MULTIPLIER)} ${SizeUnitEnum.MB}`;
58
71
  case SizeUnitEnum.GB:
59
- return `${Size.ROUNDER.round(this.bytes / Size.GB_MULTIPLIER)} ${SizeUnitEnum.GB}`;
72
+ return `${Size.FORMAT_ROUND.round(this.bytes / Size.GB_MULTIPLIER)} ${SizeUnitEnum.GB}`;
60
73
  default:
61
74
  return `${this.bytes} ${SizeUnitEnum.b}`;
62
75
  }