UNPKG

1.06 kBTypeScriptView Raw
1/**
2 * Convert the given value in bytes into a string.
3 */
4declare function bytes(value: number, options?: bytes.BytesOptions): string;
5
6/**
7 * Parse string to an integer in bytes.
8 */
9declare function bytes(value: string): number;
10
11declare namespace bytes {
12 type Unit = "b" | "gb" | "kb" | "mb" | "pb" | "tb" | "B" | "GB" | "KB" | "MB" | "PB" | "TB";
13
14 interface BytesOptions {
15 decimalPlaces?: number | undefined;
16 fixedDecimals?: boolean | undefined;
17 thousandsSeparator?: string | undefined;
18 unit?: Unit | undefined;
19 unitSeparator?: string | undefined;
20 }
21
22 /**
23 * Format the given value in bytes into a string.
24 *
25 * If the value is negative, it is kept as such.
26 * If it is a float, it is rounded.
27 */
28 function format(value: number, options?: BytesOptions): string;
29
30 /**
31 * Parse the string value into an integer in bytes.
32 *
33 * If no unit is given, it is assumed the value is in bytes.
34 */
35 function parse(value: string | number): number;
36}
37
38export = bytes;