@@ -34,40 +34,27 @@ export function bytesToSize(bytes: number) {
3434 return val . toPrecision ( 3 ) + sizes [ i ] ;
3535}
3636
37- function formatMbWithMaxFractionDigits ( value : number , fractionDigits ?: number ) : string {
38- if ( isNumeric ( fractionDigits ) ) {
39- const fixed = value . toFixed ( fractionDigits ) ;
40- const trimmed = fixed . replace ( / \. ? 0 + $ / , '' ) ;
41-
42- return trimmed === '' ? '0' : trimmed ;
43- }
44-
45- if ( value < 10 ) {
46- return value . toFixed ( 2 ) ;
47- } else if ( value < 100 ) {
48- return value . toFixed ( 1 ) ;
49- }
50-
51- return value . toFixed ( ) ;
52- }
53-
54- export function bytesToMB (
55- bytes ?: number | string ,
56- fractionDigits ?: number ,
57- withThousandsGrouping ?: boolean ,
58- ) {
37+ export function bytesToMB ( bytes ?: number | string , fractionDigits ?: number ) {
5938 const bytesNumber = Number ( bytes ) ;
6039 if ( isNaN ( bytesNumber ) ) {
6140 return '' ;
6241 }
6342
6443 const val = bytesNumber / base ** 2 ;
6544
66- const roundedStr = formatMbWithMaxFractionDigits ( val , fractionDigits ) ;
45+ if ( isNumeric ( fractionDigits ) ) {
46+ const rounded = Number ( val . toFixed ( fractionDigits ) ) ;
6747
68- const result = withThousandsGrouping ? formatNumber ( roundedStr ) : roundedStr ;
48+ return String ( rounded ) + sizes [ 2 ] ;
49+ }
6950
70- return `${ result } ${ sizes [ 2 ] } ` ;
51+ if ( val < 10 ) {
52+ return val . toFixed ( 2 ) + sizes [ 2 ] ;
53+ } else if ( val < 100 ) {
54+ return val . toFixed ( 1 ) + sizes [ 2 ] ;
55+ } else {
56+ return val . toFixed ( ) + sizes [ 2 ] ;
57+ }
7158}
7259
7360export function bytesToSpeed ( bytes ?: number | string , fractionDigits ?: number ) {
0 commit comments