@bgord/tools 1.0.2 → 1.0.3
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/size.vo.d.ts +5 -1
- package/dist/size.vo.js +15 -5
- package/package.json +1 -1
- package/src/size.vo.ts +18 -5
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
|
|
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
|
|
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.
|
|
52
|
+
return `${Size.FORMAT_ROUND.round(this.bytes / Size.KB_MULTIPLIER)} ${SizeUnitEnum.kB}`;
|
|
43
53
|
case SizeUnitEnum.MB:
|
|
44
|
-
return `${Size.
|
|
54
|
+
return `${Size.FORMAT_ROUND.round(this.bytes / Size.MB_MULTIPLIER)} ${SizeUnitEnum.MB}`;
|
|
45
55
|
case SizeUnitEnum.GB:
|
|
46
|
-
return `${Size.
|
|
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
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
|
|
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.
|
|
68
|
+
return `${Size.FORMAT_ROUND.round(this.bytes / Size.KB_MULTIPLIER)} ${SizeUnitEnum.kB}`;
|
|
56
69
|
case SizeUnitEnum.MB:
|
|
57
|
-
return `${Size.
|
|
70
|
+
return `${Size.FORMAT_ROUND.round(this.bytes / Size.MB_MULTIPLIER)} ${SizeUnitEnum.MB}`;
|
|
58
71
|
case SizeUnitEnum.GB:
|
|
59
|
-
return `${Size.
|
|
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
|
}
|