Update prettyBytes.md

This commit is contained in:
Angelos Chalaris
2018-01-01 20:00:50 +02:00
committed by GitHub
parent 63bafe6595
commit 6c26c15e23

View File

@ -8,8 +8,7 @@ Return the prettified string by building it up, taking into account the supplied
negative or not.
```js
const prettyBytes = (num, options) => {
options = { precision: 3, addSpace: true, ...options };
const prettyBytes = (num, precision = 3, addSpace = true) {
const UNITS = ['B','KB','MB','GB','TB','PB','EB','ZB','YB'];
if (num < 1) return (num < 0 ? '-' : '') + num + ' B';
const exponent = Math.min(Math.floor(Math.log10(num < 0 ? -num : num) / 3), UNITS.length - 1);