Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
dist/ | 12-May-2024 | - | 153 | 52 | ||
LICENSE | D | 12-May-2024 | 1.1 KiB | 22 | 17 | |
README.hbs | D | 12-May-2024 | 1.4 KiB | 41 | 27 | |
README.md | D | 12-May-2024 | 3.7 KiB | 134 | 103 | |
index.mjs | D | 12-May-2024 | 4.3 KiB | 145 | 136 | |
package.json | D | 12-May-2024 | 2.2 KiB | 84 | 83 |
README.hbs
1[](https://www.npmjs.org/package/byte-size) 2[](https://www.npmjs.org/package/byte-size) 3[](https://travis-ci.org/75lb/byte-size) 4[](https://coveralls.io/github/75lb/byte-size?branch=master) 5[](https://david-dm.org/75lb/byte-size) 6[](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© 2014-18 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown). 41
README.md
1[](https://www.npmjs.org/package/byte-size) 2[](https://www.npmjs.org/package/byte-size) 3[](https://travis-ci.org/75lb/byte-size) 4[](https://coveralls.io/github/75lb/byte-size?branch=master) 5[](https://david-dm.org/75lb/byte-size) 6[](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>"metric"</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© 2014-18 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown). 134