UNPKG

1.91 kBMarkdownView Raw
1# React Pretty Bytes
2
3> Convert bytes to a human readable string `1337` → `1.34 kB`
4
5[![CI](https://github.com/yohix/react-pretty-bytes/workflows/CI/badge.svg)](https://github.com/yohix/react-pretty-bytes/actions)
6[![Version](http://img.shields.io/npm/v/react-pretty-bytes.svg?style=flat)](https://badge.fury.io/js/react-pretty-bytes)
7[![Downloads](https://img.shields.io/npm/dm/react-pretty-bytes.svg)](https://npmjs.com/react-pretty-bytes)
8[![Install size](https://badgen.net/packagephobia/install/react-pretty-bytes)](https://packagephobia.now.sh/result?p=react-pretty-bytes)
9
10[![NPM](https://nodei.co/npm/react-pretty-bytes.png?downloads=true)](https://nodei.co/npm/react-pretty-bytes)
11
12## Try in CodeSandbox
13
14[![Edit react-camelcase](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/react-pretty-bytes-ypfx8?fontsize=14&hidenavigation=1&theme=dark)
15
16## Install
17
18```
19$ npm install react-pretty-bytes
20```
21
22## Usage
23
24```js
25import PrettyBytes from 'react-pretty-bytes';
26
27const App = () => (
28 <div>
29 <PrettyBytes bytes={1337} />
30 </div>
31);
32
33// => '1.34 kB'
34```
35
36## API
37
38### number={input}
39
40Type: `integer`
41
42```jsx
43<PrettyBytes bytes={1337} />
44
45// => '1.34 kB'
46```
47
48### option={object}
49
50Type: `object`
51
52#### `{bits: true}`
53
54Type: `boolean`
55Default: `false`
56
57```jsx
58<PrettyBytes bytes={1337} option={{bits: true}} />
59
60// => '1.34 kbit'
61```
62```jsx
63<PrettyBytes bytes={1337} option={{bits: true}} />
64
65// => '1.34 kbit'
66```
67
68#### `{signed: true}`
69
70Type: `boolean`
71Default: `false`
72
73```jsx
74<PrettyBytes bytes={1337} option={{signed: true}} />
75
76// => '+42 B'
77```
78
79#### `{locale: 'lang'}`
80
81Type: `boolean` `string`
82Default: `false`
83
84```jsx
85<PrettyBytes bytes={1337} option={{locale: 'de'}} />
86
87// => '1,34 kB'
88```
89
90## Modules used
91
92- [**pretty-bytes**](https://www.npmjs.com/package/pretty-bytes) - Convert bytes to a human readable string
93
94## License
95
96MIT © [Yohix](LICENSE)