Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 2.0.1 to 2.0.2

88

lib/filesize.js

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

* @module filesize
* @version 2.0.1
* @version 2.0.2
*/

@@ -16,5 +16,4 @@ ( function ( global ) {

var bit = /b$/,
bite = /^B$/,
radix = 10,
right = /\.(.*)/,
left = /.*\./,
zero = /^0$/;

@@ -33,4 +32,3 @@

skip = false,
i = 6,
base, bits, neg, num, round, size, sizes, unix, spacer, suffix, z, suffixes;
e, base, bits, ceil, neg, num, round, unix, spacer, suffix, z, suffixes;

@@ -50,2 +48,3 @@ if ( isNaN( arg ) ) {

neg = ( num < 0 );
ceil = base > 2 ? 1000 : 1024;

@@ -68,42 +67,47 @@ // Flipping a negative number to determine the size

else {
sizes = options[base][bits ? "bits" : "bytes"];
e = Math.floor( Math.log( num ) / Math.log( 1000 ) );
while ( i-- ) {
size = sizes[i][1];
suffix = sizes[i][0];
if ( base === 2 ) {
result = num / Math.pow( 2, ( e * 10 ) );
}
else {
result = num / Math.pow( 1000, e );
}
if ( num >= size ) {
// Treating bytes as cardinal
if ( bite.test( suffix ) ) {
skip = true;
round = 0;
}
if ( bits ) {
result = ( result * 8 );
result = ( num / size ).toFixed( round );
if ( result > ceil ) {
result = result / ceil;
e++;
}
}
if ( !skip && unix ) {
if ( bits && bit.test( suffix ) ) {
suffix = suffix.toLowerCase();
}
result = result.toFixed( e > 0 ? round : 0 );
suffix = si[bits ? "bits" : "bytes"][e];
suffix = suffix.charAt( 0 );
z = right.exec( result );
if ( !skip && unix ) {
if ( bits && bit.test( suffix ) ) {
suffix = suffix.toLowerCase();
}
if ( !bits && suffix === "k" ) {
suffix = "K";
}
suffix = suffix.charAt( 0 );
z = result.replace( left, "" );
if ( z !== null && z[1] !== undefined && zero.test( z[1] ) ) {
result = parseInt( result, radix );
}
if ( suffix === "B" ) {
suffix = "";
}
else if ( !bits && suffix === "k" ) {
suffix = "K";
}
result += spacer + ( suffixes[suffix] || suffix );
}
else if ( !unix ) {
result += spacer + ( suffixes[suffix] || suffix );
}
if ( zero.test( z ) ) {
result = parseInt( result, radix );
}
break;
}
result += spacer + ( suffixes[suffix] || suffix );
}
else if ( !unix ) {
result += spacer + ( suffixes[suffix] || suffix );
}
}

@@ -120,15 +124,9 @@

/**
* Size options
* SI suffixes
*
* @type {Object}
*/
var options = {
2 : {
bits : [["B", 1], ["kb", 128], ["Mb", 131072], ["Gb", 134217728], ["Tb", 137438953472], ["Pb", 140737488355328]],
bytes : [["B", 1], ["kB", 1024], ["MB", 1048576], ["GB", 1073741824], ["TB", 1099511627776], ["PB", 1125899906842624]]
},
10 : {
bits : [["B", 1], ["kb", 125], ["Mb", 125000], ["Gb", 125000000], ["Tb", 125000000000], ["Pb", 125000000000000]],
bytes : [["B", 1], ["kB", 1000], ["MB", 1000000], ["GB", 1000000000], ["TB", 1000000000000], ["PB", 1000000000000000]]
}
var si = {
bits : ["B", "kb", "Mb", "Gb", "Tb", "Pb"],
bytes : ["B", "kB", "MB", "GB", "TB", "PB"]
};

@@ -135,0 +133,0 @@

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

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

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