1 | /**
|
2 | * Represents the amount of digital storage.
|
3 | *
|
4 | * The amount can be specified either as a literal value (e.g: `10`) which
|
5 | * cannot be negative, or as an unresolved number token.
|
6 | *
|
7 | * When the amount is passed as a token, unit conversion is not possible.
|
8 | */
|
9 | export declare class Size {
|
10 | /**
|
11 | * Create a Storage representing an amount kibibytes.
|
12 | * 1 KiB = 1024 bytes
|
13 | *
|
14 | * @param amount the amount of kibibytes to be represented
|
15 | *
|
16 | * @returns a new `Size` instance
|
17 | */
|
18 | static kibibytes(amount: number): Size;
|
19 | /**
|
20 | * Create a Storage representing an amount mebibytes.
|
21 | * 1 MiB = 1024 KiB
|
22 | *
|
23 | * @param amount the amount of mebibytes to be represented
|
24 | *
|
25 | * @returns a new `Size` instance
|
26 | */
|
27 | static mebibytes(amount: number): Size;
|
28 | /**
|
29 | * Create a Storage representing an amount gibibytes.
|
30 | * 1 GiB = 1024 MiB
|
31 | *
|
32 | * @param amount the amount of gibibytes to be represented
|
33 | *
|
34 | * @returns a new `Size` instance
|
35 | */
|
36 | static gibibytes(amount: number): Size;
|
37 | /**
|
38 | * Create a Storage representing an amount tebibytes.
|
39 | * 1 TiB = 1024 GiB
|
40 | *
|
41 | * @param amount the amount of tebibytes to be represented
|
42 | *
|
43 | * @returns a new `Size` instance
|
44 | */
|
45 | static tebibytes(amount: number): Size;
|
46 | /**
|
47 | * Create a Storage representing an amount pebibytes.
|
48 | * 1 PiB = 1024 TiB
|
49 | *
|
50 | * @deprecated use `pebibytes` instead
|
51 | */
|
52 | static pebibyte(amount: number): Size;
|
53 | /**
|
54 | * Create a Storage representing an amount pebibytes.
|
55 | * 1 PiB = 1024 TiB
|
56 | *
|
57 | * @param amount the amount of pebibytes to be represented
|
58 | *
|
59 | * @returns a new `Size` instance
|
60 | */
|
61 | static pebibytes(amount: number): Size;
|
62 | private readonly amount;
|
63 | private readonly unit;
|
64 | private constructor();
|
65 | /**
|
66 | * Return this storage as a total number of kibibytes.
|
67 | *
|
68 | * @param opts the conversion options
|
69 | *
|
70 | * @returns the quantity of bytes expressed in kibibytes
|
71 | */
|
72 | toKibibytes(opts?: SizeConversionOptions): number;
|
73 | /**
|
74 | * Return this storage as a total number of mebibytes.
|
75 | *
|
76 | * @param opts the conversion options
|
77 | *
|
78 | * @returns the quantity of bytes expressed in mebibytes
|
79 | */
|
80 | toMebibytes(opts?: SizeConversionOptions): number;
|
81 | /**
|
82 | * Return this storage as a total number of gibibytes.
|
83 | *
|
84 | * @param opts the conversion options
|
85 | *
|
86 | * @returns the quantity of bytes expressed in gibibytes
|
87 | */
|
88 | toGibibytes(opts?: SizeConversionOptions): number;
|
89 | /**
|
90 | * Return this storage as a total number of tebibytes.
|
91 | *
|
92 | * @param opts the conversion options
|
93 | *
|
94 | * @returns the quantity of bytes expressed in tebibytes
|
95 | */
|
96 | toTebibytes(opts?: SizeConversionOptions): number;
|
97 | /**
|
98 | * Return this storage as a total number of pebibytes.
|
99 | *
|
100 | * @param opts the conversion options
|
101 | *
|
102 | * @returns the quantity of bytes expressed in pebibytes
|
103 | */
|
104 | toPebibytes(opts?: SizeConversionOptions): number;
|
105 | /**
|
106 | * Checks if size is a token or a resolvable object
|
107 | */
|
108 | isUnresolved(): boolean;
|
109 | }
|
110 | /**
|
111 | * Rounding behaviour when converting between units of `Size`.
|
112 | */
|
113 | export declare enum SizeRoundingBehavior {
|
114 | /** Fail the conversion if the result is not an integer. */
|
115 | FAIL = 0,
|
116 | /** If the result is not an integer, round it to the closest integer less than the result */
|
117 | FLOOR = 1,
|
118 | /** Don't round. Return even if the result is a fraction. */
|
119 | NONE = 2
|
120 | }
|
121 | /**
|
122 | * Options for how to convert time to a different unit.
|
123 | */
|
124 | export interface SizeConversionOptions {
|
125 | /**
|
126 | * How conversions should behave when it encounters a non-integer result
|
127 | * @default SizeRoundingBehavior.FAIL
|
128 | */
|
129 | readonly rounding?: SizeRoundingBehavior;
|
130 | }
|