MCPcopy Create free account
hub / github.com/avoidwork/filesize.js / filesize

Function filesize

src/filesize.js:50–188  ·  view source on GitHub ↗
(
	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,
	} = {},
)

Source from the content-addressed store, hash-verified

48 * filesize(1024, {output: "object"}) // {value: 1.02, symbol: "kB", exponent: 1, unit: "kB"}
49 */
50export 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,

Callers 6

filesize.test.jsFile · 0.90
stress-test.jsFile · 0.90
partialFunction · 0.85

Calls 9

getBaseConfigurationFunction · 0.90
handleZeroValueFunction · 0.90
calculateExponentFunction · 0.90
calculateOptimizedValueFunction · 0.90
applyRoundingFunction · 0.90
applyPrecisionHandlingFunction · 0.90
resolveSymbolFunction · 0.90
decorateResultFunction · 0.90
formatOutputFunction · 0.90

Tested by

no test coverage detected