Skip to content

Commit

Permalink
Correcting dir structure
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Aug 15, 2012
1 parent cc36eac commit c42ae05
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 4 deletions.
4 changes: 2 additions & 2 deletions grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function(grunt) {
"<banner>",
"src/filesize.js"
],
dest : "dist/filesize.js"
dest : "lib/filesize.js"
}
},
test : {
Expand All @@ -29,7 +29,7 @@ module.exports = function(grunt) {
files : ["grunt.js"]
},
min : {
"dist/filesize.min.js" : ["<banner>", "dist/filesize.js"]
"lib/filesize.min.js" : ["<banner>", "lib/filesize.js"]
},
watch : {
files : "<config:lint.files>",
Expand Down
File renamed without changes.
File renamed without changes.
70 changes: 70 additions & 0 deletions lib/filesize.js
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);
11 changes: 11 additions & 0 deletions lib/filesize.min.js
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);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"url": "http://opensource.org/licenses/BSD-3-Clause"
}
],
"main": "dist/filesize",
"main": "lib/filesize",
"engines": {
"node": ">= 0.6.0"
},
Expand Down
2 changes: 1 addition & 1 deletion test/filesize_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var filesize = require("../dist/filesize.js");
var filesize = require("../lib/filesize.js");

exports["filesize"] = {
setUp: function (done) {
Expand Down

0 comments on commit c42ae05

Please sign in to comment.