source: trip-planner-front/node_modules/pretty-bytes/readme.md@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.6 KB
Line 
1# pretty-bytes
2
3> Convert bytes to a human readable string: `1337` → `1.34 kB`
4
5Useful for displaying file sizes for humans.
6
7*Note that it uses base-10 (e.g. kilobyte).
8[Read about the difference between kilobyte and kibibyte.](https://web.archive.org/web/20150324153922/https://pacoup.com/2009/05/26/kb-kb-kib-whats-up-with-that/)*
9
10## Install
11
12```
13$ npm install pretty-bytes
14```
15
16## Usage
17
18```js
19const prettyBytes = require('pretty-bytes');
20
21prettyBytes(1337);
22//=> '1.34 kB'
23
24prettyBytes(100);
25//=> '100 B'
26
27// Display with units of bits
28prettyBytes(1337, {bits: true});
29//=> '1.34 kbit'
30
31// Display file size differences
32prettyBytes(42, {signed: true});
33//=> '+42 B'
34
35// Localized output using German locale
36prettyBytes(1337, {locale: 'de'});
37//=> '1,34 kB'
38```
39
40## API
41
42### prettyBytes(number, options?)
43
44#### number
45
46Type: `number`
47
48The number to format.
49
50#### options
51
52Type: `object`
53
54##### signed
55
56Type: `boolean`\
57Default: `false`
58
59Include plus sign for positive numbers. If the difference is exactly zero a space character will be prepended instead for better alignment.
60
61##### bits
62
63Type: `boolean`\
64Default: `false`
65
66Format the number as [bits](https://en.wikipedia.org/wiki/Bit) instead of [bytes](https://en.wikipedia.org/wiki/Byte). This can be useful when, for example, referring to [bit rate](https://en.wikipedia.org/wiki/Bit_rate).
67
68##### binary
69
70Type: `boolean`\
71Default: `false`
72
73Format the number using the [Binary Prefix](https://en.wikipedia.org/wiki/Binary_prefix) instead of the [SI Prefix](https://en.wikipedia.org/wiki/SI_prefix). This can be useful for presenting memory amounts. However, this should not be used for presenting file sizes.
74
75##### locale
76
77Type: `boolean | string`\
78Default: `false` *(No localization)*
79
80**Important:** Only the number and decimal separator are localized. The unit title is not and will not be localized.
81
82- If `true`: Localize the output using the system/browser locale.
83- If `string`: Expects a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) (For example: `en`, `de`, …)
84- If `string[]`: Expects a list of [BCP 47 language tags](https://en.wikipedia.org/wiki/IETF_language_tag) (For example: `en`, `de`, …)
85
86**Note:** Localization should generally work in browsers. Node.js needs to be [built](https://github.com/nodejs/node/wiki/Intl) with `full-icu` or `system-icu`. Alternatively, the [`full-icu`](https://github.com/unicode-org/full-icu-npm) module can be used to provide support at runtime. [Node.js 13](https://nodejs.org/en/blog/release/v13.0.0/) and later ships with ICU by default.
87
88##### minimumFractionDigits
89
90Type: `number`\
91Default: `undefined`
92
93The minimum number of fraction digits to display.
94
95If neither `minimumFractionDigits` or `maximumFractionDigits` are set, the default behavior is to round to 3 significant digits.
96
97```js
98const prettyBytes = require('pretty-bytes');
99
100// Show the number with at least 3 fractional digits
101prettyBytes(1900, {minimumFractionDigits: 3});
102//=> '1.900 kB'
103
104prettyBytes(1900);
105//=> '1.9 kB'
106```
107
108##### maximumFractionDigits
109
110Type: `number`\
111Default: `undefined`
112
113The maximum number of fraction digits to display.
114
115If neither `minimumFractionDigits` or `maximumFractionDigits` are set, the default behavior is to round to 3 significant digits.
116
117```js
118const prettyBytes = require('pretty-bytes');
119
120// Show the number with at most 1 fractional digit
121prettyBytes(1920, {maximumFractionDigits: 1});
122//=> '1.9 kB'
123
124prettyBytes(1920);
125//=> '1.92 kB'
126```
127
128## Related
129
130- [pretty-bytes-cli](https://github.com/sindresorhus/pretty-bytes-cli) - CLI for this module
131- [pretty-ms](https://github.com/sindresorhus/pretty-ms) - Convert milliseconds to a human readable string
Note: See TracBrowser for help on using the repository browser.