UNPKG

1.75 kBMarkdownView Raw
1# Installation
2> `npm install --save @types/bytes`
3
4# Summary
5This package contains type definitions for bytes (https://github.com/visionmedia/bytes.js).
6
7# Details
8Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/bytes.
9## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/bytes/index.d.ts)
10````ts
11/**
12 * Convert the given value in bytes into a string.
13 */
14declare function bytes(value: number, options?: bytes.BytesOptions): string;
15
16/**
17 * Parse string to an integer in bytes.
18 */
19declare function bytes(value: string): number;
20
21declare namespace bytes {
22 type Unit = "b" | "gb" | "kb" | "mb" | "pb" | "tb" | "B" | "GB" | "KB" | "MB" | "PB" | "TB";
23
24 interface BytesOptions {
25 decimalPlaces?: number | undefined;
26 fixedDecimals?: boolean | undefined;
27 thousandsSeparator?: string | undefined;
28 unit?: Unit | undefined;
29 unitSeparator?: string | undefined;
30 }
31
32 /**
33 * Format the given value in bytes into a string.
34 *
35 * If the value is negative, it is kept as such.
36 * If it is a float, it is rounded.
37 */
38 function format(value: number, options?: BytesOptions): string;
39
40 /**
41 * Parse the string value into an integer in bytes.
42 *
43 * If no unit is given, it is assumed the value is in bytes.
44 */
45 function parse(value: string | number): number;
46}
47
48export = bytes;
49
50````
51
52### Additional Details
53 * Last updated: Mon, 06 Nov 2023 22:41:05 GMT
54 * Dependencies: none
55
56# Credits
57These definitions were written by [Zhiyuan Wang](https://github.com/danny8002), [Rickard Laurin](https://github.com/believer), and [Florian Keller](https://github.com/ffflorian).
58
\No newline at end of file