@@ -110,7 +110,7 @@ __webpack_require__.d(string_namespaceObject, "truncate", function() { return st
110
110
var other_namespaceObject = { } ;
111
111
__webpack_require__ . r ( other_namespaceObject ) ;
112
112
__webpack_require__ . d ( other_namespaceObject , "currency" , function ( ) { return other_currency ; } ) ;
113
- __webpack_require__ . d ( other_namespaceObject , "fileSize " , function ( ) { return other_fileSize ; } ) ;
113
+ __webpack_require__ . d ( other_namespaceObject , "bytes " , function ( ) { return other_bytes ; } ) ;
114
114
__webpack_require__ . d ( other_namespaceObject , "pluralize" , function ( ) { return other_pluralize ; } ) ;
115
115
__webpack_require__ . d ( other_namespaceObject , "ordinal" , function ( ) { return other_ordinal ; } ) ;
116
116
__webpack_require__ . d ( other_namespaceObject , "number" , function ( ) { return other_number ; } ) ;
@@ -572,40 +572,44 @@ function toFixed(num, precision) {
572
572
}
573
573
574
574
/* harmony default export */ var other_currency = ( currency ) ;
575
- // CONCATENATED MODULE: ./src/other/fileSize.js
575
+ // CONCATENATED MODULE: ./src/other/bytes.js
576
+
576
577
/**
577
578
* 8 => '8 byte'
578
579
* 1024 => '1.00 kb'
579
580
* 2000000 => '1.90 MB'
580
581
* 2000000000 => '1.86 GB'
581
582
* 2000000000000 => '1.82 TB'
582
583
*
583
- * @param {Number } valueInBytes The file size in bytes
584
+ * @param {Number } value
584
585
* @param {Number } decimals Decimal places (default: 2)
585
586
*/
586
- function fileSize ( valueInBytes ) {
587
- var decimals = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : 2 ;
588
- valueInBytes = valueInBytes === null || isNaN ( valueInBytes ) ? 0 : valueInBytes ;
589
587
590
- if ( valueInBytes >= Math . pow ( 1024 , 4 ) ) {
588
+ function bytes ( value , decimals ) {
589
+ var globalOptions = this && this . bytes ? this . bytes : { } ;
590
+ decimals = src_util . exist ( decimals ) ? decimals : globalOptions . decimalDigits ;
591
+ decimals = typeof decimals !== 'undefined' ? decimals : 2 ;
592
+ value = value === null || isNaN ( value ) ? 0 : value ;
593
+
594
+ if ( value >= Math . pow ( 1024 , 4 ) ) {
591
595
// TB
592
- return "" . concat ( ( valueInBytes / Math . pow ( 1024 , 4 ) ) . toFixed ( decimals ) , " TB" ) ;
593
- } else if ( valueInBytes >= Math . pow ( 1024 , 3 ) ) {
596
+ return "" . concat ( ( value / Math . pow ( 1024 , 4 ) ) . toFixed ( decimals ) , " TB" ) ;
597
+ } else if ( value >= Math . pow ( 1024 , 3 ) ) {
594
598
// GB
595
- return "" . concat ( ( valueInBytes / Math . pow ( 1024 , 3 ) ) . toFixed ( decimals ) , " GB" ) ;
596
- } else if ( valueInBytes >= Math . pow ( 1024 , 2 ) ) {
599
+ return "" . concat ( ( value / Math . pow ( 1024 , 3 ) ) . toFixed ( decimals ) , " GB" ) ;
600
+ } else if ( value >= Math . pow ( 1024 , 2 ) ) {
597
601
// MB
598
- return "" . concat ( ( valueInBytes / Math . pow ( 1024 , 2 ) ) . toFixed ( decimals ) , " MB" ) ;
599
- } else if ( valueInBytes >= 1024 ) {
602
+ return "" . concat ( ( value / Math . pow ( 1024 , 2 ) ) . toFixed ( decimals ) , " MB" ) ;
603
+ } else if ( value >= 1024 ) {
600
604
// kb
601
- return "" . concat ( ( valueInBytes / 1024 ) . toFixed ( decimals ) , " kb" ) ;
605
+ return "" . concat ( ( value / 1024 ) . toFixed ( decimals ) , " kb" ) ;
602
606
} // byte
603
607
604
608
605
- return "" . concat ( valueInBytes , " byte" ) ;
609
+ return "" . concat ( value , " byte" ) ;
606
610
}
607
611
608
- /* harmony default export */ var other_fileSize = ( fileSize ) ;
612
+ /* harmony default export */ var other_bytes = ( bytes ) ;
609
613
// CONCATENATED MODULE: ./src/other/pluralize.js
610
614
611
615
/**
0 commit comments