byte-parser
Version:
Parse byte string to byte number, e.g. 1.2 Kb -> 1228.8, Kb, Mb, Gb, Tb, Pb, Eb, Zb, Yb supported.
36 lines (23 loc) • 1.05 kB
Markdown
byte string to byte number, e.g. `1.2 Kb` -> `1228.8`, Kb, Mb, Gb, Tb, Pb, Eb, Zb, Yb supported.
[](https://www.npmjs.com/package/byte-parser)
[](https://github.com/hustcc/byte-parser/actions)
[](https://www.npmjs.com/package/byte-parser)
[](https://www.npmjs.com/package/byte-parser)
```bash
$ npm i --save-dev byte-parser
```
```ts
import parse from 'byte-parser';
parse('100'); // 100
parse('10.1 b'); // 10.1
parse('10.1 KB'); // 10.1 * 1024
parse('10.1 kb', 1000); // 10.1 * 1000
parse('1.2 mb'); // 1.2 * 1024 * 1024
parse('1.2 Gb'); // 1.2 * 1024 * 1024 * 1024
parse('1.2 G'); // 1.2 * 1024 * 1024 * 1024
```
MIT@[hustcc](https://github.com/hustcc).
> Parse