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