3 [![NPM Version][npm-image]][npm-url]
4 [![NPM Downloads][downloads-image]][downloads-url]
5 [![Build Status][travis-image]][travis-url]
7 Utility to parse a string bytes (ex: `1TB`) to bytes (`1099511627776`) and vice-versa.
12 var bytes = require('bytes');
15 #### bytes.format(number value, [options]): string|null
17 Format the given value in bytes into a string. If the value is negative, it is kept as such. If it is a float, it is
22 | Name | Type | Description |
23 |---------|--------|--------------------|
24 | value | `number` | Value in bytes |
25 | options | `Object` | Conversion options |
29 | Property | Type | Description |
30 |-------------------|--------|-----------------------------------------------------------------------------------------|
31 | decimalPlaces | `number`|`null` | Maximum number of decimal places to include in output. Default value to `2`. |
32 | fixedDecimals | `boolean`|`null` | Whether to always display the maximum number of decimal places. Default value to `false` |
33 | thousandsSeparator | `string`|`null` | Example of values: `' '`, `','` and `.`... Default value to `' '`. |
37 | Name | Type | Description |
38 |---------|-------------|-------------------------|
39 | results | `string`|`null` | Return null upon error. String value otherwise. |
50 bytes(1000, {thousandsSeparator: ' '});
53 bytes(1024 * 1.7, {decimalPlaces: 0});
57 #### bytes.parse(string value): number|null
59 Parse the string value into an integer in bytes. If no unit is given, it is assumed the value is in bytes.
63 | Name | Type | Description |
64 |---------------|--------|--------------------|
65 | value | `string` | String to parse. |
69 | Name | Type | Description |
70 |---------|-------------|-------------------------|
71 | results | `number`|`null` | Return null upon error. Value in bytes otherwise. |
86 npm install bytes --save
87 component install visionmedia/bytes.js
92 [![npm](https://img.shields.io/npm/l/express.svg)](https://github.com/visionmedia/bytes.js/blob/master/LICENSE)
94 [downloads-image]: https://img.shields.io/npm/dm/bytes.svg
95 [downloads-url]: https://npmjs.org/package/bytes
96 [npm-image]: https://img.shields.io/npm/v/bytes.svg
97 [npm-url]: https://npmjs.org/package/bytes
98 [travis-image]: https://img.shields.io/travis/visionmedia/bytes.js/master.svg
99 [travis-url]: https://travis-ci.org/visionmedia/bytes.js