Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor changes #11

Merged
merged 1 commit into from
Nov 3, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @license BSD-3 <http://opensource.org/licenses/BSD-3-Clause>
* @link https://github.com/avoidwork/filesize.js
* @module filesize
* @version 1.7.1
* @version 1.7.2
*/

(function (global) {
Expand All @@ -22,7 +22,7 @@
*/
var filesize = function (arg) {
var base = 10,
pos, short, num, sizes, size, result, regex, suffix, i, z;
bit, byte, i, num, pos, regex, result, short, size, sizes, suffix, z, zero;

if (typeof arguments[2] !== "undefined") {
pos = arguments[1];
Expand All @@ -39,18 +39,21 @@
i = sizes.length;
result = "";
regex = /\.(.*)/;
bit = /b$/;
byte = /^B$/;
zero = /^0$/;

while (i--) {
size = sizes[i][1];
suffix = sizes[i][0];
if (i > 3) size = Number(size);
if (num >= size) {
result = (suffix === "B" ? num : (num / size)).toFixed(pos);
result = (byte.test(suffix) ? num : (num / size)).toFixed(pos);
if (short) {
if (/b$/.test(suffix)) suffix = suffix.toLowerCase();
if (bit.test(suffix)) suffix = suffix.toLowerCase();
suffix = suffix.slice(0, 1);
z = regex.exec(result);
if (z !== null && typeof z[1] !== "undefined" && z[1] === "0") result = parseInt(result, base);
if (z !== null && typeof z[1] !== "undefined" && zero.test(z[1])) result = parseInt(result, base);
}
result += suffix;
break;
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.7.1",
"version": "1.7.2",
"homepage": "https://github.com/avoidwork/filesize.js",
"author": {
"name": "Jason Mulligan",
Expand Down
11 changes: 7 additions & 4 deletions src/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
var filesize = function (arg) {
var base = 10,
pos, short, num, sizes, size, result, regex, suffix, i, z;
bit, byte, i, num, pos, regex, result, short, size, sizes, suffix, z, zero;

if (typeof arguments[2] !== "undefined") {
pos = arguments[1];
Expand All @@ -28,18 +28,21 @@
i = sizes.length;
result = "";
regex = /\.(.*)/;
bit = /b$/;
byte = /^B$/;
zero = /^0$/;

while (i--) {
size = sizes[i][1];
suffix = sizes[i][0];
if (i > 3) size = Number(size);
if (num >= size) {
result = (suffix === "B" ? num : (num / size)).toFixed(pos);
result = (byte.test(suffix) ? num : (num / size)).toFixed(pos);
if (short) {
if (/b$/.test(suffix)) suffix = suffix.toLowerCase();
if (bit.test(suffix)) suffix = suffix.toLowerCase();
suffix = suffix.slice(0, 1);
z = regex.exec(result);
if (z !== null && typeof z[1] !== "undefined" && z[1] === "0") result = parseInt(result, base);
if (z !== null && typeof z[1] !== "undefined" && zero.test(z[1])) result = parseInt(result, base);
}
result += suffix;
break;
Expand Down