Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

filesize

Package Overview
Dependencies
Maintainers
1
Versions
141
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.0.2
to
3.1.0
+145
lib/filesize.es6.js
/**
* filesize
*
* @author Jason Mulligan <jason.mulligan@avoidwork.com>
* @copyright 2015 Jason Mulligan
* @license BSD-3 <https://raw.github.com/avoidwork/filesize.js/master/LICENSE>
* @link http://filesizejs.com
* @module filesize
* @version 3.1.0
*/
( global ) => {
const bit = /b$/;
/**
* filesize
*
* @method filesize
* @param {Mixed} arg String, Int or Float to transform
* @param {Object} descriptor [Optional] Flags
* @return {String} Readable file size String
*/
let 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" );
}
descriptor = descriptor || {};
bits = ( descriptor.bits === true );
unix = ( descriptor.unix === true );
base = descriptor.base !== undefined ? descriptor.base : 2;
round = descriptor.round !== undefined ? descriptor.round : unix ? 1 : 2;
spacer = descriptor.spacer !== undefined ? descriptor.spacer : unix ? "" : " ";
suffixes = descriptor.suffixes !== undefined ? descriptor.suffixes : {};
output = descriptor.output !== undefined ? descriptor.output : "string";
e = descriptor.exponent !== undefined ? descriptor.exponent : -1;
num = Number( arg );
neg = ( num < 0 );
ceil = base > 2 ? 1000 : 1024;
// Flipping a negative number to determine the size
if ( neg ) {
num = -num;
}
// 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 {
// Determining the exponent
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 ) );
e = 8;
}
if ( base === 2 ) {
val = num / Math.pow( 2, ( e * 10 ) );
} else {
val = num / Math.pow( 1000, e );
}
if ( bits ) {
val = ( val * 8 );
if ( val > ceil ) {
val = val / ceil;
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();
}
result[ 1 ] = result[ 1 ].charAt( 0 );
if ( result[ 1 ] === "B" ) {
result[ 0 ] = Math.floor( result[ 0 ] );
result[ 1 ] = "";
} else if ( !bits && result[ 1 ] === "k" ) {
result[ 1 ] = "K";
}
}
}
// Decorating a 'diff'
if ( neg ) {
result[ 0 ] = -result[ 0 ];
}
// Applying custom suffix
result[ 1 ] = suffixes[ result[ 1 ] ] || result[ 1 ];
// Returning Array, Object, or String (default)
if ( output === "array" ) {
return result;
} else if ( output === "exponent" ) {
return e;
} else if ( output === "object" ) {
return { value: result[ 0 ], suffix: result[ 1 ] };
} else {
return result.join( spacer );
}
}
/**
* SI suffixes
*
* @type {Object}
*/
const si = {
bits: [ "B", "kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb" ],
bytes: [ "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" ]
};
// CommonJS, AMD, script tag
if ( typeof exports !== "undefined" ) {
module.exports = filesize;
} else if ( typeof define === "function" ) {
define( () => {
return filesize;
} );
} else {
global.filesize = filesize;
}
}( this );
+61
-31

@@ -50,3 +50,3 @@ <?xml version="1.0" encoding="UTF-8"?>

<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="2106">
<state vertical-scroll-proportion="0.0" vertical-offset="78" max-vertical-offset="2106">
<caret line="6" column="30" selection-start-line="0" selection-start-column="0" selection-end-line="156" selection-end-column="0" />

@@ -61,4 +61,4 @@ <folding />

<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.10743801" vertical-offset="0" max-vertical-offset="598">
<caret line="3" column="19" selection-start-line="3" selection-start-column="19" selection-end-line="3" selection-end-column="19" />
<state vertical-scroll-proportion="0.25714287" vertical-offset="0" max-vertical-offset="598">
<caret line="9" column="17" selection-start-line="9" selection-start-column="17" selection-end-line="9" selection-end-column="17" />
<folding />

@@ -147,4 +147,4 @@ </state>

<component name="ProjectFrameBounds">
<option name="width" value="1440" />
<option name="height" value="900" />
<option name="width" value="1920" />
<option name="height" value="1080" />
</component>

@@ -247,16 +247,9 @@ <component name="ProjectLevelVcsManager" settingsEditedManually="false">

<component name="RunManager">
<configuration default="true" type="DartUnitRunConfigurationType" factoryName="DartUnit">
<configuration default="true" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application">
<method />
</configuration>
<configuration default="true" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application">
<configuration default="true" type="DartUnitRunConfigurationType" factoryName="DartUnit">
<method />
</configuration>
<configuration default="true" type="BashConfigurationType" factoryName="Bash">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="INTERPRETER_PATH" value="/bin/bash" />
<option name="WORKING_DIRECTORY" value="" />
<option name="PARENT_ENVS" value="true" />
<option name="SCRIPT_NAME" value="" />
<option name="PARAMETERS" value="" />
<module name="" />
<configuration default="true" type="JavaScriptTestRunnerKarma" factoryName="Karma" config-file="">
<envs />

@@ -272,3 +265,10 @@ <method />

</configuration>
<configuration default="true" type="JavaScriptTestRunnerKarma" factoryName="Karma" config-file="">
<configuration default="true" type="BashConfigurationType" factoryName="Bash">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="INTERPRETER_PATH" value="/bin/bash" />
<option name="WORKING_DIRECTORY" value="" />
<option name="PARENT_ENVS" value="true" />
<option name="SCRIPT_NAME" value="" />
<option name="PARAMETERS" value="" />
<module name="" />
<envs />

@@ -314,6 +314,6 @@ <method />

<component name="ToolWindowManager">
<frame x="0" y="0" width="1440" height="900" extended-state="0" />
<editor active="false" />
<frame x="0" y="0" width="1920" height="1080" extended-state="0" />
<editor active="true" />
<layout>
<window_info id="Grunt" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.49131513" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Grunt" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.4908722" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />

@@ -324,5 +324,3 @@ <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.3292683" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />

<window_info id="Application Servers" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.11627907" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.11585045" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />

@@ -333,7 +331,9 @@ <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />

<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="SLIDING" type="SLIDING" visible="false" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
</layout>

@@ -378,2 +378,34 @@ </component>

</entry>
<entry file="file://$PROJECT_DIR$/lib/filesize.js">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="78" max-vertical-offset="2106">
<caret line="6" column="30" selection-start-line="0" selection-start-column="0" selection-end-line="156" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/package.json">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="598">
<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/filesize_test.js">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="39" max-vertical-offset="1690">
<caret line="27" column="101" selection-start-line="27" selection-start-column="101" selection-end-line="27" selection-end-column="101" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/filesize.js">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="442" max-vertical-offset="1599">
<caret line="45" column="9" selection-start-line="45" selection-start-column="9" selection-end-line="45" selection-end-column="9" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/filesize.min.js">

@@ -383,3 +415,2 @@ <provider selected="true" editor-type-id="text-editor">

<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding />
</state>

@@ -389,11 +420,10 @@ </provider>

<entry file="file://$PROJECT_DIR$/lib/filesize.min.js.map">
<provider editor-type-id="sourcemapFileViewerProvider">
<state />
</provider>
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="754">
<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding />
</state>
</provider>
<provider editor-type-id="sourcemapFileViewerProvider">
<state />
</provider>
</entry>

@@ -410,4 +440,4 @@ <entry file="file://$PROJECT_DIR$/lib/filesize.js">

<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.10743801" vertical-offset="0" max-vertical-offset="598">
<caret line="3" column="19" selection-start-line="3" selection-start-column="19" selection-end-line="3" selection-end-column="19" />
<state vertical-scroll-proportion="0.25714287" vertical-offset="0" max-vertical-offset="598">
<caret line="9" column="17" selection-start-line="9" selection-start-column="17" selection-end-line="9" selection-end-column="17" />
<folding />

@@ -414,0 +444,0 @@ </state>

@@ -0,1 +1,3 @@

"use strict";
/**

@@ -9,149 +11,148 @@ * filesize

* @module filesize
* @version 3.0.2
* @version 3.1.0
*/
( function ( global ) {
"use strict";
(function (global) {
var bit = /b$/;
var bit = /b$/;
/**
* filesize
*
* @method filesize
* @param {Mixed} arg String, Int or Float to transform
* @param {Object} descriptor [Optional] Flags
* @return {String} Readable file size String
*/
var filesize = function (arg, descriptor) {
var result = [],
skip = false,
val = 0,
e = undefined,
base = undefined,
bits = undefined,
ceil = undefined,
neg = undefined,
num = undefined,
output = undefined,
round = undefined,
unix = undefined,
spacer = undefined,
suffixes = undefined;
/**
* filesize
*
* @method filesize
* @param {Mixed} arg String, Int or Float to transform
* @param {Object} descriptor [Optional] Flags
* @return {String} Readable file size String
*/
function filesize ( arg, descriptor ) {
var 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" );
}
descriptor = descriptor || {};
bits = descriptor.bits === true;
unix = descriptor.unix === true;
base = descriptor.base !== undefined ? descriptor.base : 2;
round = descriptor.round !== undefined ? descriptor.round : unix ? 1 : 2;
spacer = descriptor.spacer !== undefined ? descriptor.spacer : unix ? "" : " ";
suffixes = descriptor.suffixes !== undefined ? descriptor.suffixes : {};
output = descriptor.output !== undefined ? descriptor.output : "string";
e = descriptor.exponent !== undefined ? descriptor.exponent : -1;
num = Number(arg);
neg = num < 0;
ceil = base > 2 ? 1000 : 1024;
descriptor = descriptor || {};
bits = ( descriptor.bits === true );
unix = ( descriptor.unix === true );
base = descriptor.base !== undefined ? descriptor.base : 2;
round = descriptor.round !== undefined ? descriptor.round : unix ? 1 : 2;
spacer = descriptor.spacer !== undefined ? descriptor.spacer : unix ? "" : " ";
suffixes = descriptor.suffixes !== undefined ? descriptor.suffixes : {};
output = descriptor.output !== undefined ? descriptor.output : "string";
e = descriptor.exponent !== undefined ? descriptor.exponent : -1;
num = Number( arg );
neg = ( num < 0 );
ceil = base > 2 ? 1000 : 1024;
// Flipping a negative number to determine the size
if (neg) {
num = -num;
}
// Flipping a negative number to determine the size
if ( neg ) {
num = -num;
}
// Zero is now a special case because bytes divide by 1
if (num === 0) {
result[0] = 0;
// 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 {
// Determining the exponent
if (e === -1 || isNaN(e)) {
e = Math.floor(Math.log(num) / Math.log(ceil));
}
if ( unix ) {
result[ 1 ] = "";
}
else {
result[ 1 ] = "B";
}
}
else {
// Determining the exponent
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));
e = 8;
}
// Exceeding supported length, time to reduce & multiply
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);
}
if ( base === 2 ) {
val = num / Math.pow( 2, ( e * 10 ) );
}
else {
val = num / Math.pow( 1000, e );
}
if (bits) {
val = val * 8;
if ( bits ) {
val = ( val * 8 );
if (val > ceil) {
val = val / ceil;
e++;
}
}
if ( val > ceil ) {
val = val / ceil;
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 ) {
if ( bits && bit.test( result[ 1 ] ) ) {
result[ 1 ] = result[ 1 ].toLowerCase();
}
result[1] = result[1].charAt(0);
result[ 1 ] = result[ 1 ].charAt( 0 );
if (result[1] === "B") {
result[0] = Math.floor(result[0]);
result[1] = "";
} else if (!bits && result[1] === "k") {
result[1] = "K";
}
}
}
if ( result[ 1 ] === "B" ) {
result[ 0 ] = Math.floor( result[ 0 ] );
result[ 1 ] = "";
}
else if ( !bits && result[ 1 ] === "k" ) {
result[ 1 ] = "K";
}
}
}
// Decorating a 'diff'
if (neg) {
result[0] = -result[0];
}
// Decorating a 'diff'
if ( neg ) {
result[ 0 ] = -result[ 0 ];
}
// Applying custom suffix
result[1] = suffixes[result[1]] || result[1];
// Applying custom suffix
result[ 1 ] = suffixes[ result[ 1 ] ] || result[ 1 ];
// Returning Array, Object, or String (default)
if (output === "array") {
return result;
} else if (output === "exponent") {
return e;
} else if (output === "object") {
return { value: result[0], suffix: result[1] };
} else {
return result.join(spacer);
}
};
// Returning Array, Object, or String (default)
if ( output === "array" ) {
return result;
}
else if ( output === "exponent" ) {
return e;
}
else if ( output === "object" ) {
return { value: result[ 0 ], suffix: result[ 1 ] };
}
else {
return result.join( spacer );
}
}
/**
* SI suffixes
*
* @type {Object}
*/
var si = {
bits: ["B", "kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"],
bytes: ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
};
/**
* SI suffixes
*
* @type {Object}
*/
var si = {
bits: [ "B", "kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb" ],
bytes: [ "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" ]
};
// CommonJS, AMD, script tag
if ( typeof exports !== "undefined" ) {
module.exports = filesize;
}
else if ( typeof define === "function" ) {
define( function () {
return filesize;
} );
}
else {
global.filesize = filesize;
}
} )( this );
// CommonJS, AMD, script tag
if (typeof exports !== "undefined") {
module.exports = filesize;
} else if (typeof define === "function") {
define(function () {
return filesize;
});
} else {
global.filesize = filesize;
}
})(this);

@@ -1,1 +0,1 @@

{"version":3,"file":"filesize.min.js","sources":["filesize.js"],"names":["global","filesize","arg","descriptor","e","base","bits","ceil","neg","num","output","round","unix","spacer","suffixes","result","skip","val","isNaN","Error","undefined","exponent","Number","Math","floor","log","pow","toFixed","si","bit","test","toLowerCase","charAt","value","suffix","join","bytes","exports","module","define","this"],"mappings":";;;;CAUA,SAAaA,GACb,YAYA,SAASC,GAAWC,EAAKC,GACxB,GAGCC,GAAGC,EAAMC,EAAMC,EAAMC,EAAKC,EAAKC,EAAQC,EAAOC,EAAMC,EAAQC,EAHzDC,KACHC,GAAO,EACPC,EAAM,CAGP,IAAKC,MAAOhB,GACX,KAAM,IAAIiB,OAAO,oBAyFlB,OAtFAhB,GAAaA,MACbG,EAASH,EAAWG,QAAS,EAC7BM,EAAST,EAAWS,QAAS,EAC7BP,EAA2Be,SAApBjB,EAAWE,KAAqBF,EAAWE,KAAO,EACzDM,EAA6BS,SAArBjB,EAAWQ,MAAsBR,EAAWQ,MAAQC,EAAO,EAAI,EACvEC,EAA+BO,SAAtBjB,EAAWU,OAAuBV,EAAWU,OAASD,EAAO,GAAK,IAC3EE,EAAmCM,SAAxBjB,EAAWW,SAAyBX,EAAWW,YAC1DJ,EAA+BU,SAAtBjB,EAAWO,OAAuBP,EAAWO,OAAS,SAC/DN,EAA4BgB,SAAxBjB,EAAWkB,SAAyBlB,EAAWkB,SAAW,GAC9DZ,EAAMa,OAAQpB,GACdM,EAAc,EAANC,EACRF,EAAOF,EAAO,EAAI,IAAO,KAGpBG,IACJC,GAAOA,GAIK,IAARA,GACJM,EAAQ,GAAM,EAGbA,EAAQ,GADJH,EACU,GAGA,OAKJ,KAANR,G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015 Jason Mulligan\n * @license BSD-3 <https://raw.github.com/avoidwork/filesize.js/master/LICENSE>\n * @link http://filesizejs.com\n * @module filesize\n * @version 3.0.2\n */\n( function ( global ) {\n\"use strict\";\n\nvar bit = /b$/;\n\n/**\n * filesize\n *\n * @method filesize\n * @param {Mixed} arg String, Int or Float to transform\n * @param {Object} descriptor [Optional] Flags\n * @return {String} Readable file size String\n */\nfunction filesize ( arg, descriptor ) {\n\tvar result = [],\n\t\tskip = false,\n\t\tval = 0,\n\t\te, base, bits, ceil, neg, num, output, round, unix, spacer, suffixes;\n\n\tif ( isNaN( arg ) ) {\n\t\tthrow new Error( \"Invalid arguments\" );\n\t}\n\n\tdescriptor = descriptor || {};\n\tbits = ( descriptor.bits === true );\n\tunix = ( descriptor.unix === true );\n\tbase = descriptor.base !== undefined ? descriptor.base : 2;\n\tround = descriptor.round !== undefined ? descriptor.round : unix ? 1 : 2;\n\tspacer = descriptor.spacer !== undefined ? descriptor.spacer : unix ? \"\" : \" \";\n\tsuffixes = descriptor.suffixes !== undefined ? descriptor.suffixes : {};\n\toutput = descriptor.output !== undefined ? descriptor.output : \"string\";\n\te = descriptor.exponent !== undefined ? descriptor.exponent : -1;\n\tnum = Number( arg );\n\tneg = ( num < 0 );\n\tceil = base > 2 ? 1000 : 1024;\n\n\t// Flipping a negative number to determine the size\n\tif ( neg ) {\n\t\tnum = -num;\n\t}\n\n\t// Zero is now a special case because bytes divide by 1\n\tif ( num === 0 ) {\n\t\tresult[ 0 ] = 0;\n\n\t\tif ( unix ) {\n\t\t\tresult[ 1 ] = \"\";\n\t\t}\n\t\telse {\n\t\t\tresult[ 1 ] = \"B\";\n\t\t}\n\t}\n\telse {\n\t\t// Determining the exponent\n\t\tif ( e === -1 || isNaN( e ) ) {\n\t\t\te = Math.floor( Math.log( num ) / Math.log( ceil ) );\n\t\t}\n\n\t\t// Exceeding supported length, time to reduce & multiply\n\t\tif ( e > 8 ) {\n\t\t\tval = val * ( 1000 * ( e - 8 ) );\n\t\t\te = 8;\n\t\t}\n\n\t\tif ( base === 2 ) {\n\t\t\tval = num / Math.pow( 2, ( e * 10 ) );\n\t\t}\n\t\telse {\n\t\t\tval = num / Math.pow( 1000, e );\n\t\t}\n\n\t\tif ( bits ) {\n\t\t\tval = ( val * 8 );\n\n\t\t\tif ( val > ceil ) {\n\t\t\t\tval = val / ceil;\n\t\t\t\te++;\n\t\t\t}\n\t\t}\n\n\t\tresult[ 0 ] = Number( val.toFixed( e > 0 ? round : 0 ) );\n\t\tresult[ 1 ] = si[ bits ? \"bits\" : \"bytes\" ][ e ];\n\n\t\tif ( !skip && unix ) {\n\t\t\tif ( bits && bit.test( result[ 1 ] ) ) {\n\t\t\t\tresult[ 1 ] = result[ 1 ].toLowerCase();\n\t\t\t}\n\n\t\t\tresult[ 1 ] = result[ 1 ].charAt( 0 );\n\n\t\t\tif ( result[ 1 ] === \"B\" ) {\n\t\t\t\tresult[ 0 ] = Math.floor( result[ 0 ] );\n\t\t\t\tresult[ 1 ] = \"\";\n\t\t\t}\n\t\t\telse if ( !bits && result[ 1 ] === \"k\" ) {\n\t\t\t\tresult[ 1 ] = \"K\";\n\t\t\t}\n\t\t}\n\t}\n\n\t// Decorating a 'diff'\n\tif ( neg ) {\n\t\tresult[ 0 ] = -result[ 0 ];\n\t}\n\n\t// Applying custom suffix\n\tresult[ 1 ] = suffixes[ result[ 1 ] ] || result[ 1 ];\n\n\t// Returning Array, Object, or String (default)\n\tif ( output === \"array\" ) {\n\t\treturn result;\n\t}\n\telse if ( output === \"exponent\" ) {\n\t\treturn e;\n\t}\n\telse if ( output === \"object\" ) {\n\t\treturn { value: result[ 0 ], suffix: result[ 1 ] };\n\t}\n\telse {\n\t\treturn result.join( spacer );\n\t}\n}\n\n/**\n * SI suffixes\n *\n * @type {Object}\n */\nvar si = {\n\tbits: [ \"B\", \"kb\", \"Mb\", \"Gb\", \"Tb\", \"Pb\", \"Eb\", \"Zb\", \"Yb\" ],\n\tbytes: [ \"B\", \"kB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\" ]\n};\n\n// CommonJS, AMD, script tag\nif ( typeof exports !== \"undefined\" ) {\n\tmodule.exports = filesize;\n}\nelse if ( typeof define === \"function\" ) {\n\tdefine( function () {\n\t\treturn filesize;\n\t} );\n}\nelse {\n\tglobal.filesize = filesize;\n}\n} )( this );\n"]}
{"version":3,"file":"filesize.min.js","sources":["filesize.js"],"names":["global","bit","filesize","arg","descriptor","result","skip","val","e","undefined","base","bits","ceil","neg","num","output","round","unix","spacer","suffixes","isNaN","Error","exponent","Number","Math","floor","log","pow","toFixed","si","test","toLowerCase","charAt","value","suffix","join","bytes","exports","module","define","this"],"mappings":";;;;AAAA,cAYA,SAAWA,GACT,GAAIC,GAAM,KAUNC,EAAW,SAAUC,EAAKC,GAC5B,GAAIC,MACAC,GAAO,EACPC,EAAM,EACNC,EAAIC,OACJC,EAAOD,OACPE,EAAOF,OACPG,EAAOH,OACPI,EAAMJ,OACNK,EAAML,OACNM,EAASN,OACTO,EAAQP,OACRQ,EAAOR,OACPS,EAAST,OACTU,EAAWV,MAEf,IAAIW,MAAMjB,GACR,KAAM,IAAIkB,OAAM,oBAqFlB,OAlFAjB,GAAaA,MACbO,EAAOP,EAAWO,QAAS,EAC3BM,EAAOb,EAAWa,QAAS,EAC3BP,EAA2BD,SAApBL,EAAWM,KAAqBN,EAAWM,KAAO,EACzDM,EAA6BP,SAArBL,EAAWY,MAAsBZ,EAAWY,MAAQC,EAAO,EAAI,EACvEC,EAA+BT,SAAtBL,EAAWc,OAAuBd,EAAWc,OAASD,EAAO,GAAK,IAC3EE,EAAmCV,SAAxBL,EAAWe,SAAyBf,EAAWe,YAC1DJ,EAA+BN,SAAtBL,EAAWW,OAAuBX,EAAWW,OAAS,SAC/DP,EAA4BC,SAAxBL,EAAWkB,SAAyBlB,EAAWkB,SAAW,GAC9DR,EAAMS,OAAOpB,GACbU,EAAY,EAANC,EACNF,EAAOF,EAAO,EAAI,IAA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";\n\n/**\n * filesize\n *\n * @author Jason Mulligan <jason.mulligan@avoidwork.com>\n * @copyright 2015 Jason Mulligan\n * @license BSD-3 <https://raw.github.com/avoidwork/filesize.js/master/LICENSE>\n * @link http://filesizejs.com\n * @module filesize\n * @version 3.1.0\n */\n(function (global) {\n var bit = /b$/;\n\n /**\n * filesize\n *\n * @method filesize\n * @param {Mixed} arg String, Int or Float to transform\n * @param {Object} descriptor [Optional] Flags\n * @return {String} Readable file size String\n */\n var filesize = function (arg, descriptor) {\n var result = [],\n skip = false,\n val = 0,\n e = undefined,\n base = undefined,\n bits = undefined,\n ceil = undefined,\n neg = undefined,\n num = undefined,\n output = undefined,\n round = undefined,\n unix = undefined,\n spacer = undefined,\n suffixes = undefined;\n\n if (isNaN(arg)) {\n throw new Error(\"Invalid arguments\");\n }\n\n descriptor = descriptor || {};\n bits = descriptor.bits === true;\n unix = descriptor.unix === true;\n base = descriptor.base !== undefined ? descriptor.base : 2;\n round = descriptor.round !== undefined ? descriptor.round : unix ? 1 : 2;\n spacer = descriptor.spacer !== undefined ? descriptor.spacer : unix ? \"\" : \" \";\n suffixes = descriptor.suffixes !== undefined ? descriptor.suffixes : {};\n output = descriptor.output !== undefined ? descriptor.output : \"string\";\n e = descriptor.exponent !== undefined ? descriptor.exponent : -1;\n num = Number(arg);\n neg = num < 0;\n ceil = base > 2 ? 1000 : 1024;\n\n // Flipping a negative number to determine the size\n if (neg) {\n num = -num;\n }\n\n // Zero is now a special case because bytes divide by 1\n if (num === 0) {\n result[0] = 0;\n\n if (unix) {\n result[1] = \"\";\n } else {\n result[1] = \"B\";\n }\n } else {\n // Determining the exponent\n if (e === -1 || isNaN(e)) {\n e = Math.floor(Math.log(num) / Math.log(ceil));\n }\n\n // Exceeding supported length, time to reduce & multiply\n if (e > 8) {\n val = val * (1000 * (e - 8));\n e = 8;\n }\n\n if (base === 2) {\n val = num / Math.pow(2, e * 10);\n } else {\n val = num / Math.pow(1000, e);\n }\n\n if (bits) {\n val = val * 8;\n\n if (val > ceil) {\n val = val / ceil;\n e++;\n }\n }\n\n result[0] = Number(val.toFixed(e > 0 ? round : 0));\n result[1] = si[bits ? \"bits\" : \"bytes\"][e];\n\n if (!skip && unix) {\n if (bits && bit.test(result[1])) {\n result[1] = result[1].toLowerCase();\n }\n\n result[1] = result[1].charAt(0);\n\n if (result[1] === \"B\") {\n result[0] = Math.floor(result[0]);\n result[1] = \"\";\n } else if (!bits && result[1] === \"k\") {\n result[1] = \"K\";\n }\n }\n }\n\n // Decorating a 'diff'\n if (neg) {\n result[0] = -result[0];\n }\n\n // Applying custom suffix\n result[1] = suffixes[result[1]] || result[1];\n\n // Returning Array, Object, or String (default)\n if (output === \"array\") {\n return result;\n } else if (output === \"exponent\") {\n return e;\n } else if (output === \"object\") {\n return { value: result[0], suffix: result[1] };\n } else {\n return result.join(spacer);\n }\n };\n\n /**\n * SI suffixes\n *\n * @type {Object}\n */\n var si = {\n bits: [\"B\", \"kb\", \"Mb\", \"Gb\", \"Tb\", \"Pb\", \"Eb\", \"Zb\", \"Yb\"],\n bytes: [\"B\", \"kB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"]\n };\n\n // CommonJS, AMD, script tag\n if (typeof exports !== \"undefined\") {\n module.exports = filesize;\n } else if (typeof define === \"function\") {\n define(function () {\n return filesize;\n });\n } else {\n global.filesize = filesize;\n }\n})(this);"]}
{
"name": "filesize",
"description": "JavaScript library to generate a human readable String describing the file size",
"version": "3.0.2",
"version": "3.1.0",
"homepage": "http://filesizejs.com",

@@ -34,4 +34,4 @@ "author": {

"grunt-sed": "~0.1",
"grunt-6to5": "^2.0.0",
"grunt-contrib-concat": "~0.1.3",
"grunt-contrib-jshint": "~0.1",
"grunt-contrib-nodeunit": "~0.1.2",

@@ -38,0 +38,0 @@ "grunt-contrib-watch": "~0.2",

# filesize.js
[![build status](https://secure.travis-ci.org/avoidwork/filesize.js.png)](http://travis-ci.org/avoidwork/filesize.js)
[![build status](https://secure.travis-ci.org/avoidwork/filesize.js.png)](http://travis-ci.org/avoidwork/filesize.js) [![Join the chat at https://gitter.im/avoidwork/filesize.js](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/avoidwork/filesize.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

@@ -5,0 +5,0 @@ filesize.js provides a simple way to get a human readable file size string from a number (float or integer) or string.