Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions dist/filesize.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ function filesize (arg, {
// Zero is now a special case because bytes divide by 1
if (num === 0) {
result[0] = 0;

if (precision > 0) {
result[0] = result[0].toPrecision(precision);
}

u = result[1] = STRINGS.symbol[standard][bits ? BITS : BYTES][e];
} else {
val = num / (base === 2 ? Math.pow(2, e * 10) : Math.pow(1000, e));
Expand All @@ -188,6 +193,17 @@ function filesize (arg, {
e++;
}

// Setting optional precision
if (precision > 0) {
result[0] = result[0].toPrecision(precision);
const [ newResult, newExponent ] = result[0].split(E);
result[0] = newResult;

if (newExponent !== undefined) {
e += parseInt(newExponent, 10);
}
}

u = result[1] = base === 10 && e === 1 ? bits ? SI_KBIT : SI_KBYTE : STRINGS.symbol[standard][bits ? BITS : BYTES][e];
}

Expand All @@ -196,12 +212,6 @@ function filesize (arg, {
result[0] = -result[0];
}

// Setting optional precision
if (precision > 0) {
result[0] = result[0].toPrecision(precision);
result[0] = result[0].split(E)[0];
}

// Applying custom symbol
result[1] = symbols[result[1]] || result[1];

Expand Down
22 changes: 16 additions & 6 deletions dist/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ function filesize (arg, {
// Zero is now a special case because bytes divide by 1
if (num === 0) {
result[0] = 0;

if (precision > 0) {
result[0] = result[0].toPrecision(precision);
}

u = result[1] = STRINGS.symbol[standard][bits ? BITS : BYTES][e];
} else {
val = num / (base === 2 ? Math.pow(2, e * 10) : Math.pow(1000, e));
Expand All @@ -184,6 +189,17 @@ function filesize (arg, {
e++;
}

// Setting optional precision
if (precision > 0) {
result[0] = result[0].toPrecision(precision);
const [ newResult, newExponent ] = result[0].split(E);
result[0] = newResult;

if (newExponent !== undefined) {
e += parseInt(newExponent, 10);
}
}

u = result[1] = base === 10 && e === 1 ? bits ? SI_KBIT : SI_KBYTE : STRINGS.symbol[standard][bits ? BITS : BYTES][e];
}

Expand All @@ -192,12 +208,6 @@ function filesize (arg, {
result[0] = -result[0];
}

// Setting optional precision
if (precision > 0) {
result[0] = result[0].toPrecision(precision);
result[0] = result[0].split(E)[0];
}

// Applying custom symbol
result[1] = symbols[result[1]] || result[1];

Expand Down
2 changes: 1 addition & 1 deletion dist/filesize.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading