Skip to content

Commit d795026

Browse files
committedApr 23, 2016
Minor optimization by looking at the exponent vs the string length
1 parent 70048cb commit d795026

File tree

5 files changed

+5
-5
lines changed

5 files changed

+5
-5
lines changed
 

‎lib/filesize.es6.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function filesize (arg, descriptor = {}) {
8787
result[1] = base === 10 && e === 1 ? bits ? "kb" : "kB" : symbol[standard][bits ? "bits" : "bytes"][e];
8888

8989
if (unix) {
90-
result[1] = standard === "jedec" ? result[1].charAt(0) : result[1].length > 1 ? result[1].replace(/B$/, "") : result[1];
90+
result[1] = standard === "jedec" ? result[1].charAt(0) : e > 0 ? result[1].replace(/B$/, "") : result[1];
9191

9292
if (b.test(result[1])) {
9393
result[0] = Math.floor(result[0]);

‎lib/filesize.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
result[1] = base === 10 && e === 1 ? bits ? "kb" : "kB" : symbol[standard][bits ? "bits" : "bytes"][e];
103103

104104
if (unix) {
105-
result[1] = standard === "jedec" ? result[1].charAt(0) : result[1].length > 1 ? result[1].replace(/B$/, "") : result[1];
105+
result[1] = standard === "jedec" ? result[1].charAt(0) : e > 0 ? result[1].replace(/B$/, "") : result[1];
106106

107107
if (b.test(result[1])) {
108108
result[0] = Math.floor(result[0]);

‎lib/filesize.min.js

+1-1
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.

‎src/filesize.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function filesize (arg, descriptor = {}) {
6767
result[1] = base === 10 && e === 1 ? bits ? "kb" : "kB" : symbol[standard][bits ? "bits" : "bytes"][e];
6868

6969
if (unix) {
70-
result[1] = standard === "jedec" ? result[1].charAt(0) : result[1].length > 1 ? result[1].replace(/B$/, "") : result[1];
70+
result[1] = standard === "jedec" ? result[1].charAt(0) : e > 0 ? result[1].replace(/B$/, "") : result[1];
7171

7272
if (b.test(result[1])) {
7373
result[0] = Math.floor(result[0]);

0 commit comments

Comments
 (0)
Please sign in to comment.