Initial commit
[yaffs-website] / node_modules / raw-body / node_modules / bytes / Readme.md
1 # Bytes utility
2
3 [![NPM Version][npm-image]][npm-url]
4 [![NPM Downloads][downloads-image]][downloads-url]
5 [![Build Status][travis-image]][travis-url]
6
7 Utility to parse a string bytes (ex: `1TB`) to bytes (`1099511627776`) and vice-versa.
8
9 ## Usage
10
11 ```js
12 var bytes = require('bytes');
13 ```
14
15 #### bytes.format(number value, [options]): string|null
16
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
18  rounded.
19
20 **Arguments**
21
22 | Name    | Type   | Description        |
23 |---------|--------|--------------------|
24 | value   | `number` | Value in bytes     |
25 | options | `Object` | Conversion options |
26
27 **Options**
28
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 `' '`. |
34 | unitSeparator | `string`|`null` | Separator to use between number and unit. Default value to `''`. |
35
36 **Returns**
37
38 | Name    | Type        | Description             |
39 |---------|-------------|-------------------------|
40 | results | `string`|`null` | Return null upon error. String value otherwise. |
41
42 **Example**
43
44 ```js
45 bytes(1024);
46 // output: '1kB'
47
48 bytes(1000);
49 // output: '1000B'
50
51 bytes(1000, {thousandsSeparator: ' '});
52 // output: '1 000B'
53
54 bytes(1024 * 1.7, {decimalPlaces: 0});
55 // output: '2kB'
56
57 bytes(1024, {unitSeparator: ' '});
58 // output: '1 kB'
59
60 ```
61
62 #### bytes.parse(string value): number|null
63
64 Parse the string value into an integer in bytes. If no unit is given, it is assumed the value is in bytes.
65
66 Supported units and abbreviations are as follows and are case-insensitive:
67
68   * "b" for bytes
69   * "kb" for kilobytes
70   * "mb" for megabytes
71   * "gb" for gigabytes
72   * "tb" for terabytes
73
74 The units are in powers of two, not ten. This means 1kb = 1024b according to this parser.
75
76 **Arguments**
77
78 | Name          | Type   | Description        |
79 |---------------|--------|--------------------|
80 | value   | `string` | String to parse.   |
81
82 **Returns**
83
84 | Name    | Type        | Description             |
85 |---------|-------------|-------------------------|
86 | results | `number`|`null` | Return null upon error. Value in bytes otherwise. |
87
88 **Example**
89
90 ```js
91 bytes('1kB');
92 // output: 1024
93
94 bytes('1024');
95 // output: 1024
96 ```
97
98 ## Installation
99
100 ```bash
101 npm install bytes --save
102 component install visionmedia/bytes.js
103 ```
104
105 ## License 
106
107 [![npm](https://img.shields.io/npm/l/express.svg)](https://github.com/visionmedia/bytes.js/blob/master/LICENSE)
108
109 [downloads-image]: https://img.shields.io/npm/dm/bytes.svg
110 [downloads-url]: https://npmjs.org/package/bytes
111 [npm-image]: https://img.shields.io/npm/v/bytes.svg
112 [npm-url]: https://npmjs.org/package/bytes
113 [travis-image]: https://img.shields.io/travis/visionmedia/bytes.js/master.svg
114 [travis-url]: https://travis-ci.org/visionmedia/bytes.js