Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Size options can be overriden #48

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* filesize
*
* @author Jason Mulligan <[email protected]>
* @copyright 2013 Jason Mulligan
* @copyright 2014 Jason Mulligan
* @license BSD-3 <https://raw.github.com/avoidwork/filesize.js/master/LICENSE>
* @link http://filesizejs.com
* @module filesize
Expand All @@ -23,9 +23,10 @@ var bit = /b$/,
* @method filesize
* @param {Mixed} arg String, Int or Float to transform
* @param {Object} descriptor [Optional] Flags
* @param {Object} options [Optional] Overrides default size options
* @return {String} Readable file size String
*/
function filesize ( arg, descriptor ) {
function filesize ( arg, descriptor, options ) {
var result = "",
skip = false,
i = 6,
Expand All @@ -49,6 +50,8 @@ function filesize ( arg, descriptor ) {
num = -num;
}

options = options || defaultOptions;

// Zero is now a special case because bytes divide by 1
if ( num === 0 ) {
if ( unix ) {
Expand Down Expand Up @@ -114,7 +117,7 @@ function filesize ( arg, descriptor ) {
*
* @type {Object}
*/
var options = {
var defaultOptions = {
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]]
Expand Down
4 changes: 2 additions & 2 deletions lib/filesize.map
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version":3,
"file":"filesize.min.js",
"lineCount":10,
"mappings":"A;;;;;;;AAUE,SAAS,CAA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CAAC,CAAC,GAAD,CAAM,CAAN,CAAD,CAAW,CAAC,IAAD,CAAO,IAAP,CAAX,CAAyB,CAAC,IAAD,CAAO,OAAP,CAAzB,CAA0C,CAAC,IAAD,CAAO,UAAP,CAA1C,CAA8D,CAAC,IAAD,CAAO,aAAP,CAA9D,CAAqF,CAAC,IAAD,CAAO,eAAP,CAArF,CAFL,CADgB,IAKf,MACI,CAAC,CAAC,GAAD,CAAM,CAAN,CAAD,CAAW,CAAC,IAAD,CAAO,GAAP,CAAX,CAAyB,CAAC,IAAD,CAAO,KAAP,CAAzB,CAA0C,CAAC,IAAD,CAAO,KAAP,CAA1C,CAA8D,CAAC,IAAD,CAAO,KAAP,CAA9D,CAAqF,CAAC,IAAD,CAAO,MAAP,CAArF,CADJ,OAEI,CAAC,CAAC,GAAD,CAAM,CAAN,CAAD,CAAW,CAAC,IAAD,CAAO,GAAP,CAAX,CAAyB,CAAC,IAAD,CAAO,GAAP,CAAzB,CAA0C,CAAC,IAAD,CAAO,GAAP,CAA1C,CAA8D,CAAC,IAAD,CAAO,IAAP,CAA9D;AAAqF,CAAC,IAAD,CAAO,IAAP,CAArF,CAFJ,CALe,CAYG,YAAxB,GAAK,MAAOe,QAAZ,CACCC,MAAAD,QADD,CACkBlC,CADlB,CAG4B,UAAvB,GAAK,MAAOoC,OAAZ,CACJA,MAAA,CAAQ,QAAS,EAAG,CACnB,MAAOpC,EADY,CAApB,CADI,CAMJD,CAAAC,SANI,CAMcA,CAlIG,CAApB,CAAA,CAqIG,IArIH;",
"sources":["filesize.js"],
"names":["global","filesize","arg","descriptor","result","skip","i","base","bits","neg","num","round","size","sizes","unix","spacer","isNaN","Error","undefined","Number","options","suffix","bite","test","toFixed","bit","toLowerCase","charAt","z","right","exec","zero","parseInt","radix","exports","module","define"]
"names":["global","filesize","arg","descriptor","options","result","skip","i","base","bits","num","round","sizes","unix","isNaN","Error","undefined","spacer","Number","neg","defaultOptions","size","suffix","bite","test","toFixed","bit","toLowerCase","charAt","z","right","exec","zero","parseInt","radix","exports","module","define"]
}
8 changes: 4 additions & 4 deletions lib/filesize.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* @method filesize
* @param {Mixed} arg String, Int or Float to transform
* @param {Object} descriptor [Optional] Flags
* @param {Object} options [Optional] Overrides default size options
* @return {String} Readable file size String
*/
function filesize ( arg, descriptor ) {
function filesize ( arg, descriptor, options ) {
var result = "",
skip = false,
i = 6,
Expand All @@ -30,6 +31,8 @@ function filesize ( arg, descriptor ) {
num = -num;
}

options = options || defaultOptions;

// Zero is now a special case because bytes divide by 1
if ( num === 0 ) {
if ( unix ) {
Expand Down
2 changes: 1 addition & 1 deletion src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @type {Object}
*/
var options = {
var defaultOptions = {
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]]
Expand Down