(
arg,
{
bits = false,
pad = false,
base = -1,
round = 2,
locale = EMPTY,
localeOptions = {},
separator = EMPTY,
spacer = SPACE,
symbols = {},
standard = EMPTY,
output = STRING,
fullform = false,
fullforms = [],
exponent = -1,
roundingMethod = ROUND,
precision = 0,
} = {},
)
| 48 | * filesize(1024, {output: "object"}) // {value: 1.02, symbol: "kB", exponent: 1, unit: "kB"} |
| 49 | */ |
| 50 | export function filesize( |
| 51 | arg, |
| 52 | { |
| 53 | bits = false, |
| 54 | pad = false, |
| 55 | base = -1, |
| 56 | round = 2, |
| 57 | locale = EMPTY, |
| 58 | localeOptions = {}, |
| 59 | separator = EMPTY, |
| 60 | spacer = SPACE, |
| 61 | symbols = {}, |
| 62 | standard = EMPTY, |
| 63 | output = STRING, |
| 64 | fullform = false, |
| 65 | fullforms = [], |
| 66 | exponent = -1, |
| 67 | roundingMethod = ROUND, |
| 68 | precision = 0, |
| 69 | } = {}, |
| 70 | ) { |
| 71 | let e = exponent, |
| 72 | num, |
| 73 | result = [], |
| 74 | val = 0, |
| 75 | u = EMPTY; |
| 76 | |
| 77 | if (typeof arg === "bigint") { |
| 78 | num = Number(arg); |
| 79 | } else { |
| 80 | num = Number(arg); |
| 81 | |
| 82 | if (isNaN(num)) { |
| 83 | throw new TypeError(INVALID_NUMBER); |
| 84 | } |
| 85 | |
| 86 | if (!isFinite(num)) { |
| 87 | throw new TypeError(INVALID_NUMBER); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | const { isDecimal, ceil, actualStandard } = getBaseConfiguration(standard, base); |
| 92 | |
| 93 | const full = fullform === true, |
| 94 | neg = num < 0, |
| 95 | roundingFunc = Math[roundingMethod]; |
| 96 | |
| 97 | if (typeof roundingFunc !== FUNCTION) { |
| 98 | throw new TypeError(INVALID_ROUND); |
| 99 | } |
| 100 | |
| 101 | if (neg) { |
| 102 | num = -num; |
| 103 | } |
| 104 | |
| 105 | if (num === 0) { |
| 106 | return handleZeroValue( |
| 107 | precision, |
no test coverage detected