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 3.1.4 to 3.1.5

.idea/watcherTasks.xml

132

lib/filesize.es6.js
/**
* filesize
*
* @author Jason Mulligan <jason.mulligan@avoidwork.com>
* @copyright 2015 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @link http://filesizejs.com
* @module filesize
* @version 3.1.4
* @version 3.1.5
*/
( global ) => {
const bit = /b$/;
(function (global) {
const b = /^(b|B)$/;
const si = {
bits: [ "B", "kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb" ],
bytes: [ "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" ]
bits: ["b", "kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"],
bytes: ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
};

@@ -26,14 +23,14 @@

*/
let filesize = ( arg, descriptor={} ) => {
let result = [];
let skip = false;
let val = 0;
let e, base, bits, ceil, neg, num, output, round, unix, spacer, suffixes;
function filesize (arg, descriptor = {}) {
let result = [],
skip = false,
val = 0,
e, base, bits, ceil, neg, num, output, round, unix, spacer, suffixes;
if ( isNaN( arg ) ) {
throw new Error( "Invalid arguments" );
if (isNaN(arg)) {
throw new Error("Invalid arguments");
}
bits = ( descriptor.bits === true );
unix = ( descriptor.unix === true );
bits = descriptor.bits === true;
unix = descriptor.unix === true;
base = descriptor.base !== undefined ? descriptor.base : 2;

@@ -45,8 +42,8 @@ round = descriptor.round !== undefined ? descriptor.round : unix ? 1 : 2;

e = descriptor.exponent !== undefined ? descriptor.exponent : -1;
num = Number( arg );
neg = ( num < 0 );
num = Number(arg);
neg = num < 0;
ceil = base > 2 ? 1000 : 1024;
// Flipping a negative number to determine the size
if ( neg ) {
if (neg) {
num = -num;

@@ -56,35 +53,22 @@ }

// Zero is now a special case because bytes divide by 1
if ( num === 0 ) {
result[ 0 ] = 0;
if ( unix ) {
result[ 1 ] = "";
}
else {
result[ 1 ] = "B";
}
}
else {
if (num === 0) {
result[0] = 0;
result[1] = unix ? "" : !bits ? "B" : "b";
} else {
// Determining the exponent
if ( e === -1 || isNaN( e ) ) {
e = Math.floor( Math.log( num ) / Math.log( ceil ) );
if (e === -1 || isNaN(e)) {
e = Math.floor(Math.log(num) / Math.log(ceil));
}
// Exceeding supported length, time to reduce & multiply
if ( e > 8 ) {
val = val * ( 1000 * ( e - 8 ) );
if (e > 8) {
e = 8;
}
if ( base === 2 ) {
val = num / Math.pow( 2, ( e * 10 ) );
}
else {
val = num / Math.pow( 1000, e );
}
val = base === 2 ? num / Math.pow(2, e * 10) : num / Math.pow(1000, e);
if ( bits ) {
val = ( val * 8 );
if (bits) {
val = val * 8;
if ( val > ceil ) {
if (val > ceil) {
val = val / ceil;

@@ -95,19 +79,14 @@ e++;

result[ 0 ] = Number( val.toFixed( e > 0 ? round : 0 ) );
result[ 1 ] = si[ bits ? "bits" : "bytes" ][ e ];
result[0] = Number(val.toFixed(e > 0 ? round : 0));
result[1] = si[bits ? "bits" : "bytes"][e];
if ( !skip && unix ) {
if ( bits && bit.test( result[ 1 ] ) ) {
result[ 1 ] = result[ 1 ].toLowerCase();
}
if (!skip && unix) {
result[1] = result[1].charAt(0);
result[ 1 ] = result[ 1 ].charAt( 0 );
if ( result[ 1 ] === "B" ) {
result[ 0 ] = Math.floor( result[ 0 ] );
result[ 1 ] = "";
if (b.test(result[1])) {
result[0] = Math.floor(result[0]);
result[1] = "";
} else if (!bits && result[1] === "k") {
result[1] = "K";
}
else if ( !bits && result[ 1 ] === "k" ) {
result[ 1 ] = "K";
}
}

@@ -117,37 +96,34 @@ }

// Decorating a 'diff'
if ( neg ) {
result[ 0 ] = -result[ 0 ];
if (neg) {
result[0] = -result[0];
}
// Applying custom suffix
result[ 1 ] = suffixes[ result[ 1 ] ] || result[ 1 ];
result[1] = suffixes[result[1]] || result[1];
// Returning Array, Object, or String (default)
if ( output === "array" ) {
if (output === "array") {
return result;
}
if ( output === "exponent" ) {
if (output === "exponent") {
return e;
}
if ( output === "object" ) {
return { value: result[ 0 ], suffix: result[ 1 ] };
if (output === "object") {
return {value: result[0], suffix: result[1]};
}
return result.join( spacer );
return result.join(spacer);
}
// CommonJS, AMD, script tag
if ( typeof exports !== "undefined" ) {
if (typeof exports !== "undefined") {
module.exports = filesize;
}
else if ( typeof define === "function" && define.amd ) {
define( () => {
} else if (typeof define === "function" && define.amd) {
define(() => {
return filesize;
} );
}
else {
});
} else {
global.filesize = filesize;
}
}( typeof global !== "undefined" ? global : window );
}}(typeof window !== "undefined" ? window : global));

@@ -0,17 +1,14 @@

"use strict";
/**
* filesize
*
* @author Jason Mulligan <jason.mulligan@avoidwork.com>
* @copyright 2015 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @link http://filesizejs.com
* @module filesize
* @version 3.1.4
* @version 3.1.5
*/
"use strict";
(function (global) {
var bit = /b$/;
var b = /^(b|B)$/;
var si = {
bits: ["B", "kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"],
bits: ["b", "kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"],
bytes: ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]

@@ -28,9 +25,9 @@ };

*/
var filesize = function (arg) {
var descriptor = arguments[1] === undefined ? {} : arguments[1];
function filesize(arg) {
var descriptor = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var result = [];
var skip = false;
var val = 0;
var e = undefined,
var result = [],
skip = false,
val = 0,
e = undefined,
base = undefined,

@@ -71,8 +68,3 @@ bits = undefined,

result[0] = 0;
if (unix) {
result[1] = "";
} else {
result[1] = "B";
}
result[1] = unix ? "" : !bits ? "B" : "b";
} else {

@@ -86,11 +78,6 @@ // Determining the exponent

if (e > 8) {
val = val * (1000 * (e - 8));
e = 8;
}
if (base === 2) {
val = num / Math.pow(2, e * 10);
} else {
val = num / Math.pow(1000, e);
}
val = base === 2 ? num / Math.pow(2, e * 10) : num / Math.pow(1000, e);

@@ -110,9 +97,5 @@ if (bits) {

if (!skip && unix) {
if (bits && bit.test(result[1])) {
result[1] = result[1].toLowerCase();
}
result[1] = result[1].charAt(0);
if (result[1] === "B") {
if (b.test(result[1])) {
result[0] = Math.floor(result[0]);

@@ -148,3 +131,3 @@ result[1] = "";

return result.join(spacer);
};
}

@@ -161,2 +144,2 @@ // CommonJS, AMD, script tag

}
})(typeof global !== "undefined" ? global : window);
})(typeof window !== "undefined" ? window : global);
{
"name": "filesize",
"description": "JavaScript library to generate a human readable String describing the file size",
"version": "3.1.4",
"version": "3.1.5",
"homepage": "http://filesizejs.com",

@@ -23,12 +23,15 @@ "author": "Jason Mulligan <jason.mulligan@avoidwork.com>",

"devDependencies": {
"grunt": "~0.4.5",
"grunt-cli": "~0.1.13",
"grunt-babel": "^4.0.0",
"grunt-sed": "~0.1.1",
"grunt-contrib-concat": "~0.5.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-watch": "~0.6.1",
"grunt-contrib-uglify": "~0.7.0"
"babel-eslint": "^4.1.4",
"babel-preset-es2015": "^6.1.2",
"grunt": "^0.4.5",
"grunt-babel": "^6.0.0",
"grunt-cli": "^0.1.13",
"grunt-contrib-concat": "^0.1.3",
"grunt-contrib-watch": "^0.2.0",
"grunt-eslint": "^17.3.1",
"grunt-contrib-nodeunit": "^0.4.1",
"grunt-contrib-uglify": "^0.9.1",
"grunt-sed": "^0.1.1"
},
"keywords": ["file", "filesize", "size", "readable", "file system"]
"keywords": ["file", "filesize", "size", "readable", "file system", "bytes", "diff"]
}

@@ -0,0 +0,0 @@ # filesize.js

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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