Socket
Socket
Sign inDemoInstall

filesize

Package Overview
Dependencies
Maintainers
1
Versions
124
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filesize - npm Package Compare versions

Comparing version 1.7.2 to 1.7.3

LICENSE

12

lib/filesize.js

@@ -5,7 +5,7 @@ /**

* @author Jason Mulligan <jason.mulligan@avoidwork.com>
* @copyright Jason Mulligan 2012
* @copyright Jason Mulligan 2013
* @license BSD-3 <http://opensource.org/licenses/BSD-3-Clause>
* @link https://github.com/avoidwork/filesize.js
* @module filesize
* @version 1.7.2
* @version 1.7.3
*/

@@ -26,3 +26,3 @@

var base = 10,
bit, byte, i, num, pos, regex, result, short, size, sizes, suffix, z, zero;
bit, byte, i, neg, num, pos, regex, result, short, size, sizes, suffix, z, zero;

@@ -40,2 +40,3 @@ if (typeof arguments[2] !== "undefined") {

num = Number(arg);
neg = (num < 0);
sizes = [["B", 0], ["Kb", 128], ["KB", 1024], ["Mb", 131072], ["MB", "1.049e+6"], ["Gb", "1.342e+8"], ["GB", "1.074e+9"], ["Tb", "1.374e+11"], ["TB", "1.1e+12"], ["Pb", "1.407e+14"], ["PB", "1.126e+15"]];

@@ -49,2 +50,5 @@ i = sizes.length;

// Flipping a negative number to determine the size
if (neg) num = num - (num * 2);
while (i--) {

@@ -67,3 +71,3 @@ size = sizes[i][1];

return result;
return (neg ? "-" : "") + result;
};

@@ -70,0 +74,0 @@

@@ -5,8 +5,8 @@ /**

* @author Jason Mulligan <jason.mulligan@avoidwork.com>
* @copyright Jason Mulligan 2012
* @copyright Jason Mulligan 2013
* @license BSD-3 <http://opensource.org/licenses/BSD-3-Clause>
* @link https://github.com/avoidwork/filesize.js
* @module filesize
* @version 1.7.2
* @version 1.7.3
*/
(function(e){"use strict";var t=function(e){var t=10,n,r,i,s,o,u,a,f,l,c,h,p,d;typeof arguments[2]!="undefined"?(o=arguments[1],f=arguments[2]):typeof arguments[1]=="boolean"?f=arguments[1]:o=arguments[1];if(isNaN(e)||typeof o!="undefined"&&isNaN(o))throw Error("Invalid arguments");f=f===!0,o=f?1:typeof o=="undefined"?2:parseInt(o,t),s=Number(e),c=[["B",0],["Kb",128],["KB",1024],["Mb",131072],["MB","1.049e+6"],["Gb","1.342e+8"],["GB","1.074e+9"],["Tb","1.374e+11"],["TB","1.1e+12"],["Pb","1.407e+14"],["PB","1.126e+15"]],i=c.length,a="",u=/\.(.*)/,n=/b$/,r=/^B$/,d=/^0$/;while(i--){l=c[i][1],h=c[i][0],i>3&&(l=Number(l));if(s>=l){a=(r.test(h)?s:s/l).toFixed(o),f&&(n.test(h)&&(h=h.toLowerCase()),h=h.slice(0,1),p=u.exec(a),p!==null&&typeof p[1]!="undefined"&&d.test(p[1])&&(a=parseInt(a,t))),a+=h;break}}return a};switch(!0){case typeof exports!="undefined":module.exports=t;break;case typeof define=="function":define(function(){return t});break;default:e.filesize=t}})(this);
(function(e){"use strict";var t=function(e){var t=10,n,r,i,s,o,u,a,f,l,c,h,p,d,v;typeof arguments[2]!="undefined"?(u=arguments[1],l=arguments[2]):typeof arguments[1]=="boolean"?l=arguments[1]:u=arguments[1];if(isNaN(e)||typeof u!="undefined"&&isNaN(u))throw Error("Invalid arguments");l=l===!0,u=l?1:typeof u=="undefined"?2:parseInt(u,t),o=Number(e),s=o<0,h=[["B",0],["Kb",128],["KB",1024],["Mb",131072],["MB","1.049e+6"],["Gb","1.342e+8"],["GB","1.074e+9"],["Tb","1.374e+11"],["TB","1.1e+12"],["Pb","1.407e+14"],["PB","1.126e+15"]],i=h.length,f="",a=/\.(.*)/,n=/b$/,r=/^B$/,v=/^0$/,s&&(o-=o*2);while(i--){c=h[i][1],p=h[i][0],i>3&&(c=Number(c));if(o>=c){f=(r.test(p)?o:o/c).toFixed(u),l&&(n.test(p)&&(p=p.toLowerCase()),p=p.slice(0,1),d=a.exec(f),d!==null&&typeof d[1]!="undefined"&&v.test(d[1])&&(f=parseInt(f,t))),f+=p;break}}return(s?"-":"")+f};switch(!0){case typeof exports!="undefined":module.exports=t;break;case typeof define=="function":define(function(){return t});break;default:e.filesize=t}})(this);
{
"name": "filesize",
"description": "JavaScript library to generate a human readable String describing the file size",
"version": "1.7.2",
"version": "1.7.3",
"homepage": "https://github.com/avoidwork/filesize.js",

@@ -33,3 +33,3 @@ "author": {

},
"keywords": []
"keywords": ["file", "filesize", "size", "readable", "filesystem"]
}

@@ -14,3 +14,3 @@ (function (global) {

var base = 10,
bit, byte, i, num, pos, regex, result, short, size, sizes, suffix, z, zero;
bit, byte, i, neg, num, pos, regex, result, short, size, sizes, suffix, z, zero;

@@ -28,2 +28,3 @@ if (typeof arguments[2] !== "undefined") {

num = Number(arg);
neg = (num < 0);
sizes = [["B", 0], ["Kb", 128], ["KB", 1024], ["Mb", 131072], ["MB", "1.049e+6"], ["Gb", "1.342e+8"], ["GB", "1.074e+9"], ["Tb", "1.374e+11"], ["TB", "1.1e+12"], ["Pb", "1.407e+14"], ["PB", "1.126e+15"]];

@@ -37,2 +38,5 @@ i = sizes.length;

// Flipping a negative number to determine the size
if (neg) num = num - (num * 2);
while (i--) {

@@ -55,3 +59,3 @@ size = sizes[i][1];

return result;
return (neg ? "-" : "") + result;
};

@@ -58,0 +62,0 @@

@@ -9,14 +9,17 @@ var filesize = require("../lib/filesize.js");

this.Kb = 500;
this.neg = -1024;
done();
},
valid: function (test) {
test.expect(8);
test.equal(filesize(this.Kb), "3.91Kb", "Should match");
test.equal(filesize(this.Kb,true), "3.9k", "Should match");
test.equal(filesize(this.num), "1.00KB", "Should match");
test.equal(filesize(this.str), "1.00KB", "Should match");
test.equal(filesize(this.num, 1), "1.0KB", "Should match");
test.equal(filesize(this.str, 1), "1.0KB", "Should match");
test.equal(filesize(this.num, true), "1K", "Should match");
test.equal(filesize(this.str, true), "1K", "Should match");
test.expect(10);
test.equal(filesize(this.Kb), "3.91Kb", "Should match");
test.equal(filesize(this.Kb,true), "3.9k", "Should match");
test.equal(filesize(this.num), "1.00KB", "Should match");
test.equal(filesize(this.str), "1.00KB", "Should match");
test.equal(filesize(this.num, 1), "1.0KB", "Should match");
test.equal(filesize(this.str, 1), "1.0KB", "Should match");
test.equal(filesize(this.num, true), "1K", "Should match");
test.equal(filesize(this.str, true), "1K", "Should match");
test.equal(filesize(this.neg), "-1.00KB", "Should match");
test.equal(filesize(this.neg, true), "-1K", "Should match");
test.done();

@@ -23,0 +26,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc