Socket
Socket
Sign inDemoInstall

filesize

Package Overview
Dependencies
0
Maintainers
1
Versions
120
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.7.0 to 1.7.1

3

lib/filesize.js

@@ -9,3 +9,3 @@ /**

* @module filesize
* @version 1.7.0
* @version 1.7.1
*/

@@ -51,2 +51,3 @@

if (short) {
if (/b$/.test(suffix)) suffix = suffix.toLowerCase();
suffix = suffix.slice(0, 1);

@@ -53,0 +54,0 @@ z = regex.exec(result);

@@ -9,4 +9,4 @@ /**

* @module filesize
* @version 1.7.0
* @version 1.7.1
*/
(function(e){"use strict";var t=function(e){var t=10,n,r,i,s,o,u,a,f,l,c;typeof arguments[2]!="undefined"?(n=arguments[1],r=arguments[2]):typeof arguments[1]=="boolean"?r=arguments[1]:n=arguments[1];if(isNaN(e)||typeof n!="undefined"&&isNaN(n))throw Error("Invalid arguments");r=r===!0,n=r?1:typeof n=="undefined"?2:parseInt(n,t),i=Number(e),s=[["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"]],l=s.length,u="",a=/\.(.*)/;while(l--){o=s[l][1],f=s[l][0],l>3&&(o=Number(o));if(i>=o){u=(f==="B"?i:i/o).toFixed(n),r&&(f=f.slice(0,1),c=a.exec(u),c!==null&&typeof c[1]!="undefined"&&c[1]==="0"&&(u=parseInt(u,t))),u+=f;break}}return u};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;typeof arguments[2]!="undefined"?(n=arguments[1],r=arguments[2]):typeof arguments[1]=="boolean"?r=arguments[1]:n=arguments[1];if(isNaN(e)||typeof n!="undefined"&&isNaN(n))throw Error("Invalid arguments");r=r===!0,n=r?1:typeof n=="undefined"?2:parseInt(n,t),i=Number(e),s=[["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"]],l=s.length,u="",a=/\.(.*)/;while(l--){o=s[l][1],f=s[l][0],l>3&&(o=Number(o));if(i>=o){u=(f==="B"?i:i/o).toFixed(n),r&&(/b$/.test(f)&&(f=f.toLowerCase()),f=f.slice(0,1),c=a.exec(u),c!==null&&typeof c[1]!="undefined"&&c[1]==="0"&&(u=parseInt(u,t))),u+=f;break}}return u};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.0",
"version": "1.7.1",
"homepage": "https://github.com/avoidwork/filesize.js",

@@ -6,0 +6,0 @@ "author": {

[![build status](https://secure.travis-ci.org/avoidwork/filesize.js.png)](http://travis-ci.org/avoidwork/filesize.js)
# filesize.js
filesize.js provides a simple way to get a human readable file size string from a number (float or integer) or string. An optional second parameter is the decimal place to round to (default is 2), or _true_ which triggers Unix style output. The maximum supported size is a terabyte. When hard drives get bigger, I'll add support for petabytes.
filesize.js provides a simple way to get a human readable file size string from a number (float or integer) or string. An optional second parameter is the decimal place to round to (default is 2), or _true_ which triggers Unix style output.

@@ -9,7 +9,9 @@ ## Examples

``` js
filesize(500); // "3.91Kb"
filesize(500, true); // "3.9k"
filesize(1500); // "1.46KB"
filesize("1500000000"); // "1.40GB"
filesize("1500000000", 0); // "1GB"
filesize(1212312421412412); // "1102.59TB"
filesize(1212312421412412, true); // "1102.6T" - shorthand output, similar to *nix "ls -lh"
filesize(1212312421412412); // "1.08PB"
filesize(1212312421412412, true); // "1.1P" - shorthand output, similar to *nix "ls -lh"
```

@@ -16,0 +18,0 @@

@@ -39,2 +39,3 @@ (function (global) {

if (short) {
if (/b$/.test(suffix)) suffix = suffix.toLowerCase();
suffix = suffix.slice(0, 1);

@@ -41,0 +42,0 @@ z = regex.exec(result);

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

this.invld = "abc";
this.Kb = 500;
done();
},
valid: function (test) {
test.expect(6);
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");

@@ -14,0 +17,0 @@ test.equal(filesize(this.str), "1.00KB", "Should match");

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc