Skip to content

Commit

Permalink
Making 0 case faster
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Apr 14, 2013
1 parent fdf8b22 commit 642966b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
13 changes: 6 additions & 7 deletions lib/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @license BSD-3 <https://raw.github.com/avoidwork/filesize.js/master/LICENSE>
* @link http://filesizejs.com
* @module filesize
* @version 1.9.2
* @version 1.9.3
*/
( function ( global ) {
"use strict";
Expand All @@ -30,11 +30,10 @@
/**
* filesize
*
* @param {Mixed} arg String, Int or Float to transform
* @param {Number} pos [Optional] Position to round to, defaults to 2 if short is ommitted
* @param {Boolean} short [Optional] Shorthand output, similar to "ls -lh", overrides pos to 1
* @param {Boolean} bits [Optional] Determines if `bit` sizes are used for result calculation, default is true
* @return {String} Readable file size String
* @param {Mixed} arg String, Int or Float to transform
* @param {Mixed} pos [Optional] Position to round to, defaults to 2 if short is ommitted, or `true` for shorthand output
* @param {Boolean} bits [Optional] Determines if `bit` sizes are used for result calculation, default is true
* @return {String} Readable file size String
*/
function filesize (arg) {
var result = "",
Expand Down Expand Up @@ -73,7 +72,7 @@

// Zero is now a special case because bytes divide by 1
if ( num === 0 ) {
result = Number( 0 ).toFixed( 0 ) + "B";
result = "0B";
}
else {
if ( bits ) {
Expand Down
4 changes: 2 additions & 2 deletions lib/filesize.min.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "filesize",
"description": "JavaScript library to generate a human readable String describing the file size",
"version": "1.9.2",
"version": "1.9.3",
"homepage": "http://filesizejs.com",
"author": {
"name": "Jason Mulligan",
Expand Down
11 changes: 5 additions & 6 deletions src/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
/**
* filesize
*
* @param {Mixed} arg String, Int or Float to transform
* @param {Number} pos [Optional] Position to round to, defaults to 2 if short is ommitted
* @param {Boolean} short [Optional] Shorthand output, similar to "ls -lh", overrides pos to 1
* @param {Boolean} bits [Optional] Determines if `bit` sizes are used for result calculation, default is true
* @return {String} Readable file size String
* @param {Mixed} arg String, Int or Float to transform
* @param {Mixed} pos [Optional] Position to round to, defaults to 2 if short is ommitted, or `true` for shorthand output
* @param {Boolean} bits [Optional] Determines if `bit` sizes are used for result calculation, default is true
* @return {String} Readable file size String
*/
function filesize (arg) {
var result = "",
Expand Down Expand Up @@ -63,7 +62,7 @@

// Zero is now a special case because bytes divide by 1
if ( num === 0 ) {
result = Number( 0 ).toFixed( 0 ) + "B";
result = "0B";
}
else {
if ( bits ) {
Expand Down

0 comments on commit 642966b

Please sign in to comment.