Skip to content

Commit 6c1d2cb

Browse files
committed
Fixing late application of pad
1 parent 8878747 commit 6c1d2cb

9 files changed

+134
-39
lines changed

lib/filesize.es6.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @copyright 2021 Jason Mulligan <[email protected]>
55
* @license BSD-3-Clause
6-
* @version 6.2.3
6+
* @version 6.2.4
77
*/
88
(function (global, factory) {
99
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -141,15 +141,6 @@
141141
result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
142142
}
143143

144-
// Returning Array, Object, or String (default)
145-
if (output === "array") {
146-
return result;
147-
}
148-
149-
if (output === "object") {
150-
return {value: result[0], symbol: result[1], exponent: e, unit: u};
151-
}
152-
153144
if (pad && Number.isInteger(result[0]) === false && round > 0) {
154145
const x = separator || ".",
155146
tmp = result[0].toString().split(x),
@@ -160,6 +151,15 @@
160151
result[0] = `${tmp[0]}${x}${s.padEnd(l + n, "0")}`;
161152
}
162153

154+
// Returning Array, Object, or String (default)
155+
if (output === "array") {
156+
return result;
157+
}
158+
159+
if (output === "object") {
160+
return {value: result[0], symbol: result[1], exponent: e, unit: u};
161+
}
162+
163163
return result.join(spacer);
164164
}
165165

lib/filesize.es6.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/filesize.es6.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/filesize.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @copyright 2021 Jason Mulligan <[email protected]>
55
* @license BSD-3-Clause
6-
* @version 6.2.3
6+
* @version 6.2.4
77
*/
88
(function (global, factory) {
99
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -157,6 +157,15 @@
157157

158158
if (full) {
159159
result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
160+
}
161+
162+
if (pad && Number.isInteger(result[0]) === false && round > 0) {
163+
var x = separator || ".",
164+
tmp = result[0].toString().split(x),
165+
s = tmp[1] || "",
166+
l = s.length,
167+
n = round - l;
168+
result[0] = "".concat(tmp[0]).concat(x).concat(s.padEnd(l + n, "0"));
160169
} // Returning Array, Object, or String (default)
161170

162171

@@ -173,15 +182,6 @@
173182
};
174183
}
175184

176-
if (pad && Number.isInteger(result[0]) === false && round > 0) {
177-
var x = separator || ".",
178-
tmp = result[0].toString().split(x),
179-
s = tmp[1] || "",
180-
l = s.length,
181-
n = round - l;
182-
result[0] = "".concat(tmp[0]).concat(x).concat(s.padEnd(l + n, "0"));
183-
}
184-
185185
return result.join(spacer);
186186
} // Partial application for functional programming
187187

lib/filesize.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/filesize.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+98-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "filesize",
33
"description": "JavaScript library to generate a human readable String describing the file size",
4-
"version": "6.2.3",
4+
"version": "6.2.4",
55
"homepage": "https://filesizejs.com",
66
"author": "Jason Mulligan <[email protected]>",
77
"repository": {

src/filesize.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,6 @@ function filesize (arg, descriptor = {}) {
128128
result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
129129
}
130130

131-
// Returning Array, Object, or String (default)
132-
if (output === "array") {
133-
return result;
134-
}
135-
136-
if (output === "object") {
137-
return {value: result[0], symbol: result[1], exponent: e, unit: u};
138-
}
139-
140131
if (pad && Number.isInteger(result[0]) === false && round > 0) {
141132
const x = separator || ".",
142133
tmp = result[0].toString().split(x),
@@ -147,6 +138,15 @@ function filesize (arg, descriptor = {}) {
147138
result[0] = `${tmp[0]}${x}${s.padEnd(l + n, "0")}`;
148139
}
149140

141+
// Returning Array, Object, or String (default)
142+
if (output === "array") {
143+
return result;
144+
}
145+
146+
if (output === "object") {
147+
return {value: result[0], symbol: result[1], exponent: e, unit: u};
148+
}
149+
150150
return result.join(spacer);
151151
}
152152

0 commit comments

Comments
 (0)