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.9.3 to 1.9.4

lib/filesize.map

72

lib/filesize.js

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

* @module filesize
* @version 1.9.3
* @version 1.9.4
*/

@@ -18,20 +18,22 @@ ( function ( global ) {

bit = /b$/,
byte = /^B$/,
bite = /^B$/,
zero = /^0$/,
options = {
all : {
increments : [["B", 1], ["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]],
nth : 11
},
bitless : {
increments : [["B", 1], ["KB", 1024], ["MB", 1.049e+6], ["GB", 1.074e+9], ["TB", 1.1e+12], ["PB", 1.126e+15]],
nth : 6
}
};
options;
options = {
all : {
increments : [["B", 1], ["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]],
nth : 11
},
bitless : {
increments : [["B", 1], ["KB", 1024], ["MB", 1.049e+6], ["GB", 1.074e+9], ["TB", 1.1e+12], ["PB", 1.126e+15]],
nth : 6
}
};
/**
* filesize
*
*
* @param {Mixed} arg String, Int or Float to transform
* @param {Mixed} pos [Optional] Position to round to, defaults to 2 if short is ommitted, or `true` for shorthand output
* @param {Mixed} pos [Optional] Position to round to, defaults to 2 if shrt is ommitted, or `true` for shrthand output
* @param {Boolean} bits [Optional] Determines if `bit` sizes are used for result calculation, default is true

@@ -44,12 +46,12 @@ * @return {String} Readable file size String

skip = false,
i, neg, num, pos, short, size, sizes, suffix, z;
i, neg, num, pos, shrt, size, sizes, suffix, z;
// Determining arguments
if (arguments[3] !== undefined) {
pos = arguments[1];
short = arguments[2];
bits = arguments[3];
pos = arguments[1];
shrt = arguments[2];
bits = arguments[3];
}
else {
typeof arguments[1] === "boolean" ? short = arguments[1] : pos = arguments[1];
typeof arguments[1] === "boolean" ? shrt = arguments[1] : pos = arguments[1];

@@ -62,10 +64,10 @@ if ( typeof arguments[2] === "boolean" ) {

if ( isNaN( arg ) || ( pos !== undefined && isNaN( pos ) ) ) {
throw Error("Invalid arguments");
throw new Error("Invalid arguments");
}
short = ( short === true );
bits = ( bits === true );
pos = short ? 1 : ( pos === undefined ? 2 : parseInt( pos, base ) );
num = Number( arg );
neg = ( num < 0 );
shrt = ( shrt === true );
bits = ( bits === true );
pos = shrt ? 1 : ( pos === undefined ? 2 : parseInt( pos, base ) );
num = Number( arg );
neg = ( num < 0 );

@@ -79,3 +81,8 @@ // Flipping a negative number to determine the size

if ( num === 0 ) {
result = "0B";
if ( shrt ) {
result = "0";
}
else {
result = "0 B";
}
}

@@ -98,3 +105,3 @@ else {

// Treating bytes as cardinal
if ( byte.test( suffix ) ) {
if ( bite.test( suffix ) ) {
skip = true;

@@ -106,3 +113,3 @@ pos = 0;

if ( !skip && short ) {
if ( !skip && shrt ) {
if ( bits && bit.test( suffix ) ) {

@@ -118,5 +125,8 @@ suffix = suffix.toLowerCase();

}
result += suffix;
}
result += suffix;
else if ( !shrt ) {
result += " " + suffix;
}
break;

@@ -133,3 +143,3 @@ }

return result;
};
}

@@ -136,0 +146,0 @@ // CommonJS, AMD, script tag

{
"name": "filesize",
"description": "JavaScript library to generate a human readable String describing the file size",
"version": "1.9.3",
"version": "1.9.4",
"homepage": "http://filesizejs.com",

@@ -31,9 +31,12 @@ "author": {

"devDependencies": {
"grunt" : "~0.4.0",
"grunt-cli" : "~ 0.1.6",
"grunt-contrib-concat" : "~ 0.1.3",
"grunt-contrib-nodeunit" : "~ 0.1.2",
"grunt-contrib-uglify" : "~ 0.1.2"
"grunt": "~0.4.1",
"grunt-cli": "~0.1.6",
"grunt-exec": "~0.4",
"grunt-sed": "~0.1",
"grunt-contrib-concat": "~0.1.3",
"grunt-contrib-jshint": "~0.1",
"grunt-contrib-nodeunit": "~0.1.2",
"grunt-contrib-watch": "~0.2"
},
"keywords": ["file", "filesize", "size", "readable", "filesystem"]
}

@@ -9,10 +9,10 @@ [![build status](https://secure.travis-ci.org/avoidwork/filesize.js.png)](http://travis-ci.org/avoidwork/filesize.js)

``` js
filesize(500); // "3.91Kb"
filesize(500); // "3.91 Kb"
filesize(500, true); // "3.9k"
filesize(1500); // "1.46KB"
filesize("1500000000"); // "1.40GB"
filesize("1500000000", 0); // "1GB"
filesize(1212312421412412); // "1.08PB"
filesize(1500); // "1.46 KB"
filesize("1500000000"); // "1.40 GB"
filesize("1500000000", 0); // "1 GB"
filesize(1212312421412412); // "1.08 PB"
filesize(1212312421412412, true); // "1.1P" - shorthand output, similar to *nix "ls -lh"
filesize(265318, 2, false) // "259.10KB" - disabled `bit` sizes with third argument
filesize(265318, 2, false) // "259.10 KB" - disabled `bit` sizes with third argument
```

@@ -19,0 +19,0 @@

Sorry, the diff of this file is not supported yet

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