|
12 | 12 | })(this, (function () { 'use strict';
|
13 | 13 |
|
14 | 14 | const strings = {
|
15 |
| - symbol: { |
16 |
| - iec: { |
17 |
| - bits: ["bit", "Kibit", "Mibit", "Gibit", "Tibit", "Pibit", "Eibit", "Zibit", "Yibit"], |
18 |
| - bytes: ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"] |
19 |
| - }, |
20 |
| - jedec: { |
21 |
| - bits: ["bit", "Kbit", "Mbit", "Gbit", "Tbit", "Pbit", "Ebit", "Zbit", "Ybit"], |
22 |
| - bytes: ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] |
23 |
| - } |
| 15 | + symbol: { |
| 16 | + iec: { |
| 17 | + bits: ["bit", "Kibit", "Mibit", "Gibit", "Tibit", "Pibit", "Eibit", "Zibit", "Yibit"], |
| 18 | + bytes: ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"] |
24 | 19 | },
|
25 |
| - fullform: { |
26 |
| - iec: ["", "kibi", "mebi", "gibi", "tebi", "pebi", "exbi", "zebi", "yobi"], |
27 |
| - jedec: ["", "kilo", "mega", "giga", "tera", "peta", "exa", "zetta", "yotta"] |
| 20 | + jedec: { |
| 21 | + bits: ["bit", "Kbit", "Mbit", "Gbit", "Tbit", "Pbit", "Ebit", "Zbit", "Ybit"], |
| 22 | + bytes: ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] |
28 | 23 | }
|
29 | 24 | },
|
30 |
| - roundingFuncs = { |
31 |
| - ceil: Math.ceil, |
32 |
| - floor: Math.floor, |
33 |
| - round: Math.round |
34 |
| - }; |
| 25 | + fullform: { |
| 26 | + iec: ["", "kibi", "mebi", "gibi", "tebi", "pebi", "exbi", "zebi", "yobi"], |
| 27 | + jedec: ["", "kilo", "mega", "giga", "tera", "peta", "exa", "zetta", "yotta"] |
| 28 | + } |
| 29 | + }; |
35 | 30 |
|
36 | 31 | /**
|
37 | 32 | * filesize
|
|
54 | 49 | const ceil = base === 10 ? 1000 : 1024,
|
55 | 50 | full = fullform === true,
|
56 | 51 | neg = num < 0,
|
57 |
| - roundingFunc = roundingFuncs[roundingMethod]; |
| 52 | + roundingFunc = Math[roundingMethod]; |
58 | 53 |
|
59 | 54 | if (isNaN(arg)) {
|
60 | 55 | throw new TypeError("Invalid number");
|
61 | 56 | }
|
62 | 57 |
|
| 58 | + if (typeof roundingFunc !== "function") { |
| 59 | + throw new TypeError("Invalid rounding method"); |
| 60 | + } |
| 61 | + |
63 | 62 | // Flipping a negative number to determine the size
|
64 | 63 | if (neg) {
|
65 | 64 | num = -num;
|
|
0 commit comments