UNPKG

1.41 kBTypeScriptView Raw
1// Type definitions for bytes 3.1
2// Project: https://github.com/visionmedia/bytes.js
3// Definitions by: Zhiyuan Wang <https://github.com/danny8002>
4// Rickard Laurin <https://github.com/believer>
5// Florian Keller <https://github.com/ffflorian>
6// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7
8/**
9 * Convert the given value in bytes into a string.
10 */
11declare function bytes(value: number, options?: bytes.BytesOptions): string;
12
13/**
14 * Parse string to an integer in bytes.
15 */
16declare function bytes(value: string): number;
17
18declare namespace bytes {
19 type Unit = 'b' | 'gb' | 'kb' | 'mb' | 'pb' | 'tb' | 'B' | 'GB' | 'KB' | 'MB' | 'PB' | 'TB';
20
21 interface BytesOptions {
22 decimalPlaces?: number | undefined;
23 fixedDecimals?: boolean | undefined;
24 thousandsSeparator?: string | undefined;
25 unit?: Unit | undefined;
26 unitSeparator?: string | undefined;
27 }
28
29 /**
30 * Format the given value in bytes into a string.
31 *
32 * If the value is negative, it is kept as such.
33 * If it is a float, it is rounded.
34 */
35 function format(value: number, options?: BytesOptions): string;
36
37 /**
38 * Parse the string value into an integer in bytes.
39 *
40 * If no unit is given, it is assumed the value is in bytes.
41 */
42 function parse(value: string | number): number;
43}
44
45export = bytes;