-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* filesize | ||
* | ||
* @author Jason Mulligan <[email protected]> | ||
* @copyright Jason Mulligan 2012 | ||
* @license BSD-3 <http://opensource.org/licenses/BSD-3-Clause> | ||
* @link https://github.com/avoidwork/filesize.js | ||
* @module filesize | ||
* @version 1.6.6 | ||
*/ | ||
|
||
(function (global) { | ||
"use strict"; | ||
|
||
/** | ||
* 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 | ||
* @return {String} Readable file size String | ||
*/ | ||
var filesize = function (arg) { | ||
var pos, short, num, sizes, size, result, regex, suffix, i, z; | ||
|
||
if (typeof arguments[2] !== "undefined") { | ||
pos = arguments[1]; | ||
short = arguments[2]; | ||
} | ||
else typeof arguments[1] === "boolean" ? short = arguments[1] : pos = arguments[1]; | ||
|
||
if (isNaN(arg) || (typeof pos !== "undefined" && isNaN(pos))) throw Error("Invalid arguments"); | ||
|
||
short = (short === true); | ||
pos = short ? 1 : (typeof pos === "undefined" ? 2 : parseInt(pos)); | ||
num = String(arg).indexOf(".") > -1 ? parseFloat(arg) : parseInt(arg); | ||
sizes = [["B", 0], ["KB", 1024], ["MB", 1048576], ["GB", 1073741824], ["TB", 1099511627776]]; | ||
i = sizes.length; | ||
result = ""; | ||
regex = /\.(.*)/; | ||
|
||
while (i--) { | ||
size = sizes[i][1]; | ||
suffix = sizes[i][0]; | ||
if (num >= size) { | ||
result = (suffix === "B" ? num : (num / size)).toFixed(pos); | ||
if (short) { | ||
suffix = suffix.slice(0, 1); | ||
z = regex.exec(result); | ||
if (z !== null && typeof z[1] !== "undefined" && z[1] === "0") result = parseInt(result); | ||
} | ||
result += suffix; | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
}; | ||
|
||
switch (true) { | ||
case typeof exports !== "undefined": | ||
module.exports = filesize; | ||
break; | ||
case typeof define === "function": | ||
define(function () { return filesize; }); | ||
break; | ||
default: | ||
global.filesize = filesize; | ||
} | ||
})(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* filesize | ||
* | ||
* @author Jason Mulligan <[email protected]> | ||
* @copyright Jason Mulligan 2012 | ||
* @license BSD-3 <http://opensource.org/licenses/BSD-3-Clause> | ||
* @link https://github.com/avoidwork/filesize.js | ||
* @module filesize | ||
* @version 1.6.6 | ||
*/ | ||
(function(a){"use strict";var b=function(a){var b,c,d,e,f,g,h,i,j,k;typeof arguments[2]!="undefined"?(b=arguments[1],c=arguments[2]):typeof arguments[1]=="boolean"?c=arguments[1]:b=arguments[1];if(isNaN(a)||typeof b!="undefined"&&isNaN(b))throw Error("Invalid arguments");c=c===!0,b=c?1:typeof b=="undefined"?2:parseInt(b),d=String(a).indexOf(".")>-1?parseFloat(a):parseInt(a),e=[["B",0],["KB",1024],["MB",1048576],["GB",1073741824],["TB",1099511627776]],j=e.length,g="",h=/\.(.*)/;while(j--){f=e[j][1],i=e[j][0];if(d>=f){g=(i==="B"?d:d/f).toFixed(b),c&&(i=i.slice(0,1),k=h.exec(g),k!==null&&typeof k[1]!="undefined"&&k[1]==="0"&&(g=parseInt(g))),g+=i;break}}return g};switch(!0){case typeof exports!="undefined":module.exports=b;break;case typeof define=="function":define(function(){return b});break;default:a.filesize=b}})(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters