Skip to content

Commit 1d19261

Browse files
committed
Removing the multiple return statements from the end of filesize(), tweaking order of final changes
1 parent ae2c8f9 commit 1d19261

9 files changed

+29
-53
lines changed

lib/filesize.es6.js

+5-13
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.4
6+
* @version 6.2.5
77
*/
88
(function (global, factory) {
99
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -137,10 +137,6 @@
137137
result[0] = result[0].toString().replace(".", separator);
138138
}
139139

140-
if (full) {
141-
result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
142-
}
143-
144140
if (pad && Number.isInteger(result[0]) === false && round > 0) {
145141
const x = separator || ".",
146142
tmp = result[0].toString().split(x),
@@ -151,16 +147,12 @@
151147
result[0] = `${tmp[0]}${x}${s.padEnd(l + n, "0")}`;
152148
}
153149

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};
150+
if (full) {
151+
result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
161152
}
162153

163-
return result.join(spacer);
154+
// Returning Array, Object, or String (default)
155+
return output === "array" ? result : output === "object" ? {value: result[0], symbol: result[1], exponent: e, unit: u} : result.join(spacer);
164156
}
165157

166158
// Partial application for functional programming

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

+11-19
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.4
6+
* @version 6.2.5
77
*/
88
(function (global, factory) {
99
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -155,34 +155,26 @@
155155
result[0] = result[0].toString().replace(".", separator);
156156
}
157157

158-
if (full) {
159-
result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
160-
}
161-
162158
if (pad && Number.isInteger(result[0]) === false && round > 0) {
163159
var x = separator || ".",
164160
tmp = result[0].toString().split(x),
165161
s = tmp[1] || "",
166162
l = s.length,
167163
n = round - l;
168164
result[0] = "".concat(tmp[0]).concat(x).concat(s.padEnd(l + n, "0"));
169-
} // Returning Array, Object, or String (default)
170-
171-
172-
if (output === "array") {
173-
return result;
174165
}
175166

176-
if (output === "object") {
177-
return {
178-
value: result[0],
179-
symbol: result[1],
180-
exponent: e,
181-
unit: u
182-
};
183-
}
167+
if (full) {
168+
result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
169+
} // Returning Array, Object, or String (default)
170+
184171

185-
return result.join(spacer);
172+
return output === "array" ? result : output === "object" ? {
173+
value: result[0],
174+
symbol: result[1],
175+
exponent: e,
176+
unit: u
177+
} : result.join(spacer);
186178
} // Partial application for functional programming
187179

188180

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

+2-2
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.4",
4+
"version": "6.2.5",
55
"homepage": "https://filesizejs.com",
66
"author": "Jason Mulligan <[email protected]>",
77
"repository": {

src/filesize.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ function filesize (arg, descriptor = {}) {
124124
result[0] = result[0].toString().replace(".", separator);
125125
}
126126

127-
if (full) {
128-
result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
129-
}
130-
131127
if (pad && Number.isInteger(result[0]) === false && round > 0) {
132128
const x = separator || ".",
133129
tmp = result[0].toString().split(x),
@@ -138,16 +134,12 @@ function filesize (arg, descriptor = {}) {
138134
result[0] = `${tmp[0]}${x}${s.padEnd(l + n, "0")}`;
139135
}
140136

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};
137+
if (full) {
138+
result[1] = fullforms[e] ? fullforms[e] : fullform[standard][e] + (bits ? "bit" : "byte") + (result[0] === 1 ? "" : "s");
148139
}
149140

150-
return result.join(spacer);
141+
// Returning Array, Object, or String (default)
142+
return output === "array" ? result : output === "object" ? {value: result[0], symbol: result[1], exponent: e, unit: u} : result.join(spacer);
151143
}
152144

153145
// Partial application for functional programming

0 commit comments

Comments
 (0)