Skip to content

Commit f877a47

Browse files
committed
Merge pull request #5 from avoidwork/edge
Correcting dir structure
2 parents bfdfb29 + c42ae05 commit f877a47

7 files changed

+85
-4
lines changed

grunt.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = function(grunt) {
1919
"<banner>",
2020
"src/filesize.js"
2121
],
22-
dest : "dist/filesize.js"
22+
dest : "lib/filesize.js"
2323
}
2424
},
2525
test : {
@@ -29,7 +29,7 @@ module.exports = function(grunt) {
2929
files : ["grunt.js"]
3030
},
3131
min : {
32-
"dist/filesize.min.js" : ["<banner>", "dist/filesize.js"]
32+
"lib/filesize.min.js" : ["<banner>", "lib/filesize.js"]
3333
},
3434
watch : {
3535
files : "<config:lint.files>",
File renamed without changes.
File renamed without changes.

lib/filesize.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* filesize
3+
*
4+
* @author Jason Mulligan <[email protected]>
5+
* @copyright Jason Mulligan 2012
6+
* @license BSD-3 <http://opensource.org/licenses/BSD-3-Clause>
7+
* @link https://github.com/avoidwork/filesize.js
8+
* @module filesize
9+
* @version 1.6.6
10+
*/
11+
12+
(function (global) {
13+
"use strict";
14+
15+
/**
16+
* filesize
17+
*
18+
* @param {Mixed} arg String, Int or Float to transform
19+
* @param {Number} pos [Optional] Position to round to, defaults to 2 if short is ommitted
20+
* @param {Boolean} short [Optional] Shorthand output, similar to "ls -lh", overrides pos to 1
21+
* @return {String} Readable file size String
22+
*/
23+
var filesize = function (arg) {
24+
var pos, short, num, sizes, size, result, regex, suffix, i, z;
25+
26+
if (typeof arguments[2] !== "undefined") {
27+
pos = arguments[1];
28+
short = arguments[2];
29+
}
30+
else typeof arguments[1] === "boolean" ? short = arguments[1] : pos = arguments[1];
31+
32+
if (isNaN(arg) || (typeof pos !== "undefined" && isNaN(pos))) throw Error("Invalid arguments");
33+
34+
short = (short === true);
35+
pos = short ? 1 : (typeof pos === "undefined" ? 2 : parseInt(pos));
36+
num = String(arg).indexOf(".") > -1 ? parseFloat(arg) : parseInt(arg);
37+
sizes = [["B", 0], ["KB", 1024], ["MB", 1048576], ["GB", 1073741824], ["TB", 1099511627776]];
38+
i = sizes.length;
39+
result = "";
40+
regex = /\.(.*)/;
41+
42+
while (i--) {
43+
size = sizes[i][1];
44+
suffix = sizes[i][0];
45+
if (num >= size) {
46+
result = (suffix === "B" ? num : (num / size)).toFixed(pos);
47+
if (short) {
48+
suffix = suffix.slice(0, 1);
49+
z = regex.exec(result);
50+
if (z !== null && typeof z[1] !== "undefined" && z[1] === "0") result = parseInt(result);
51+
}
52+
result += suffix;
53+
break;
54+
}
55+
}
56+
57+
return result;
58+
};
59+
60+
switch (true) {
61+
case typeof exports !== "undefined":
62+
module.exports = filesize;
63+
break;
64+
case typeof define === "function":
65+
define(function () { return filesize; });
66+
break;
67+
default:
68+
global.filesize = filesize;
69+
}
70+
})(this);

lib/filesize.min.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* filesize
3+
*
4+
* @author Jason Mulligan <[email protected]>
5+
* @copyright Jason Mulligan 2012
6+
* @license BSD-3 <http://opensource.org/licenses/BSD-3-Clause>
7+
* @link https://github.com/avoidwork/filesize.js
8+
* @module filesize
9+
* @version 1.6.6
10+
*/
11+
(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);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"url": "http://opensource.org/licenses/BSD-3-Clause"
2121
}
2222
],
23-
"main": "dist/filesize",
23+
"main": "lib/filesize",
2424
"engines": {
2525
"node": ">= 0.6.0"
2626
},

test/filesize_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var filesize = require("../dist/filesize.js");
1+
var filesize = require("../lib/filesize.js");
22

33
exports["filesize"] = {
44
setUp: function (done) {

0 commit comments

Comments
 (0)