• Home
Name Date Size #Lines LOC

..--

dist/12-May-2024-15352

LICENSED12-May-20241.1 KiB2217

README.hbsD12-May-20241.4 KiB4127

README.mdD12-May-20243.7 KiB134103

index.mjsD12-May-20244.3 KiB145136

package.jsonD12-May-20242.2 KiB8483

README.hbs

1[![view on npm](https://img.shields.io/npm/v/byte-size.svg)](https://www.npmjs.org/package/byte-size)
2[![npm module downloads](https://img.shields.io/npm/dt/byte-size.svg)](https://www.npmjs.org/package/byte-size)
3[![Build Status](https://travis-ci.org/75lb/byte-size.svg?branch=master)](https://travis-ci.org/75lb/byte-size)
4[![Coverage Status](https://coveralls.io/repos/github/75lb/byte-size/badge.svg?branch=master)](https://coveralls.io/github/75lb/byte-size?branch=master)
5[![Dependency Status](https://david-dm.org/75lb/byte-size.svg)](https://david-dm.org/75lb/byte-size)
6[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)
7
8{{>main}}
9
10### Load anywhere
11
12This library is compatible with Node.js, the Web and any style of module loader. It can be loaded anywhere, natively without transpilation.
13
14Node.js:
15
16```js
17const byteSize = require('byte-size')
18```
19
20Within Node.js with ECMAScript Module support enabled:
21
22```js
23import byteSize from 'byte-size'
24```
25
26Within a modern browser ECMAScript Module:
27
28```js
29import byteSize from './node_modules/byte-size/index.mjs'
30```
31
32Old browser (adds `window.byteSize`):
33
34```html
35<script nomodule src="./node_modules/byte-size/dist/index.js"></script>
36```
37
38* * *
39
40&copy; 2014-18 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).
41

README.md

1[![view on npm](https://img.shields.io/npm/v/byte-size.svg)](https://www.npmjs.org/package/byte-size)
2[![npm module downloads](https://img.shields.io/npm/dt/byte-size.svg)](https://www.npmjs.org/package/byte-size)
3[![Build Status](https://travis-ci.org/75lb/byte-size.svg?branch=master)](https://travis-ci.org/75lb/byte-size)
4[![Coverage Status](https://coveralls.io/repos/github/75lb/byte-size/badge.svg?branch=master)](https://coveralls.io/github/75lb/byte-size?branch=master)
5[![Dependency Status](https://david-dm.org/75lb/byte-size.svg)](https://david-dm.org/75lb/byte-size)
6[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)
7
8<a name="module_byte-size"></a>
9
10## byte-size
11An isomorphic, load-anywhere function to convert a bytes value into a more human-readable format. Choose between [metric or IEC units](https://en.wikipedia.org/wiki/Gigabyte), summarised below.
12
13Value | Metric
14----- | -------------
151000  | kB  kilobyte
161000^2 | MB  megabyte
171000^3 | GB  gigabyte
181000^4 | TB  terabyte
191000^5 | PB  petabyte
201000^6 | EB  exabyte
211000^7 | ZB  zettabyte
221000^8 | YB  yottabyte
23
24Value | IEC
25----- | ------------
261024  | KiB kibibyte
271024^2 | MiB mebibyte
281024^3 | GiB gibibyte
291024^4 | TiB tebibyte
301024^5 | PiB pebibyte
311024^6 | EiB exbibyte
321024^7 | ZiB zebibyte
331024^8 | YiB yobibyte
34
35Value | Metric (octet)
36----- | -------------
371000  | ko  kilooctet
381000^2 | Mo  megaoctet
391000^3 | Go  gigaoctet
401000^4 | To  teraoctet
411000^5 | Po  petaoctet
421000^6 | Eo  exaoctet
431000^7 | Zo  zettaoctet
441000^8 | Yo  yottaoctet
45
46Value | IEC (octet)
47----- | ------------
481024  | Kio kilooctet
491024^2 | Mio mebioctet
501024^3 | Gio gibioctet
511024^4 | Tio tebioctet
521024^5 | Pio pebioctet
531024^6 | Eio exbioctet
541024^7 | Zio zebioctet
551024^8 | Yio yobioctet
56
57**Example**
58```js
59const byteSize = require('byte-size')
60```
61<a name="exp_module_byte-size--byteSize"></a>
62
63### byteSize(bytes, [options]) ⇒ <code>Object</code> ⏏
64**Kind**: Exported function
65
66| Param | Type | Default | Description |
67| --- | --- | --- | --- |
68| bytes | <code>number</code> |  | the bytes value to convert. |
69| [options] | <code>object</code> |  | optional config. |
70| [options.precision] | <code>number</code> | <code>1</code> | number of decimal places. |
71| [options.units] | <code>string</code> | <code>&quot;metric&quot;</code> | select `'metric'`, `'iec'`, `'metric_octet'` or `'iec_octet'` units. |
72
73**Example**
74```js
75> const byteSize = require('byte-size')
76
77> byteSize(1580)
78{ value: '1.6', unit: 'kB' }
79
80> byteSize(1580, { units: 'iec' })
81{ value: '1.5', unit: 'KiB' }
82
83> byteSize(1580, { units: 'iec', precision: 3 })
84{ value: '1.543', unit: 'KiB' }
85
86> byteSize(1580, { units: 'iec', precision: 0 })
87{ value: '2', unit: 'KiB' }
88
89> byteSize(1580, { units: 'metric_octet' })
90{ value: '1.6', unit: 'ko' }
91
92> byteSize(1580, { units: 'iec_octet' })
93{ value: '1.5', unit: 'Kio' }
94
95> byteSize(1580, { units: 'iec_octet' }).toString()
96'1.5 Kio'
97
98> const { value, unit }  = byteSize(1580, { units: 'iec_octet' })
99> `${value} ${unit}`
100'1.5 Kio'
101```
102
103### Load anywhere
104
105This library is compatible with Node.js, the Web and any style of module loader. It can be loaded anywhere, natively without transpilation.
106
107Node.js:
108
109```js
110const byteSize = require('byte-size')
111```
112
113Within Node.js with ECMAScript Module support enabled:
114
115```js
116import byteSize from 'byte-size'
117```
118
119Within a modern browser ECMAScript Module:
120
121```js
122import byteSize from './node_modules/byte-size/index.mjs'
123```
124
125Old browser (adds `window.byteSize`):
126
127```html
128<script nomodule src="./node_modules/byte-size/dist/index.js"></script>
129```
130
131* * *
132
133&copy; 2014-18 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).
134