@@ -10,19 +10,57 @@ const els = {
1010
1111// (清理) 精简进位函数,仅保留最小所需
1212// 最小单位 MB:
13- function humanMinMBFromKB ( kb ) { if ( kb == null || isNaN ( kb ) ) return '-' ; // 输入单位: KB
14- let mb = kb / 1000 ; const units = [ 'MB' , 'GB' , 'TB' , 'PB' ] ; let i = 0 ; while ( mb >= 1000 && i < units . length - 1 ) { mb /= 1000 ; i ++ ; }
15- const out = mb >= 100 ? mb . toFixed ( 0 ) : mb . toFixed ( 1 ) ; return out + units [ i ] ; }
16- function humanMinMBFromMB ( mbVal ) { if ( mbVal == null || isNaN ( mbVal ) ) return '-' ; // 输入单位: MB
17- let v = mbVal ; const units = [ 'MB' , 'GB' , 'TB' , 'PB' ] ; let i = 0 ; while ( v >= 1000 && i < units . length - 1 ) { v /= 1000 ; i ++ ; }
18- const out = v >= 100 ? v . toFixed ( 0 ) : v . toFixed ( 1 ) ; return out + units [ i ] ; }
19- function humanMinMBFromB ( bytes ) { if ( bytes == null || isNaN ( bytes ) ) return '-' ; // 输入单位: B
20- let mb = bytes / 1000 / 1000 ; const units = [ 'MB' , 'GB' , 'TB' , 'PB' ] ; let i = 0 ; while ( mb >= 1000 && i < units . length - 1 ) { mb /= 1000 ; i ++ ; }
21- const out = mb >= 100 ? mb . toFixed ( 0 ) : mb . toFixed ( 1 ) ; return out + units [ i ] ; }
22- function humanRateMinMBFromB ( bytes ) { if ( bytes == null || isNaN ( bytes ) ) return '-' ; if ( bytes <= 0 ) return '0.0MB' ; return humanMinMBFromB ( bytes ) ; }
23- function humanMinKBFromB ( bytes ) { if ( bytes == null || isNaN ( bytes ) ) return '-' ; // 输入单位: B; 最小单位 KB
24- let kb = bytes / 1000 ; const units = [ 'KB' , 'MB' , 'GB' , 'TB' , 'PB' ] ; let i = 0 ; while ( kb >= 1000 && i < units . length - 1 ) { kb /= 1000 ; i ++ ; }
25- const out = kb >= 100 ? kb . toFixed ( 0 ) : kb . toFixed ( 1 ) ; return out + units [ i ] ; }
13+ function humanMinMBFromKB ( kb ) {
14+ if ( kb == null ) return '-' ;
15+ const n = Number ( kb ) ;
16+ if ( ! Number . isFinite ( n ) ) return '-' ;
17+ let mb = n / 1000 ; // 输入单位: KB
18+ const units = [ 'MB' , 'GB' , 'TB' , 'PB' ] ;
19+ let i = 0 ;
20+ while ( mb >= 1000 && i < units . length - 1 ) { mb /= 1000 ; i ++ ; }
21+ const out = mb >= 100 ? mb . toFixed ( 0 ) : mb . toFixed ( 1 ) ;
22+ return out + ( units [ i ] || units [ units . length - 1 ] ) ;
23+ }
24+ function humanMinMBFromMB ( mbVal ) {
25+ if ( mbVal == null ) return '-' ;
26+ const n = Number ( mbVal ) ;
27+ if ( ! Number . isFinite ( n ) ) return '-' ;
28+ let v = n ; // 输入单位: MB
29+ const units = [ 'MB' , 'GB' , 'TB' , 'PB' ] ;
30+ let i = 0 ;
31+ while ( v >= 1000 && i < units . length - 1 ) { v /= 1000 ; i ++ ; }
32+ const out = v >= 100 ? v . toFixed ( 0 ) : v . toFixed ( 1 ) ;
33+ return out + ( units [ i ] || units [ units . length - 1 ] ) ;
34+ }
35+ function humanMinMBFromB ( bytes ) {
36+ if ( bytes == null ) return '-' ;
37+ const n = Number ( bytes ) ;
38+ if ( ! Number . isFinite ( n ) ) return '-' ;
39+ let mb = n / 1000 / 1000 ; // 输入单位: B
40+ const units = [ 'MB' , 'GB' , 'TB' , 'PB' ] ;
41+ let i = 0 ;
42+ while ( mb >= 1000 && i < units . length - 1 ) { mb /= 1000 ; i ++ ; }
43+ const out = mb >= 100 ? mb . toFixed ( 0 ) : mb . toFixed ( 1 ) ;
44+ return out + ( units [ i ] || units [ units . length - 1 ] ) ;
45+ }
46+ function humanRateMinMBFromB ( bytes ) {
47+ if ( bytes == null ) return '-' ;
48+ const n = Number ( bytes ) ;
49+ if ( ! Number . isFinite ( n ) ) return '-' ;
50+ if ( n <= 0 ) return '0.0MB' ;
51+ return humanMinMBFromB ( n ) ;
52+ }
53+ function humanMinKBFromB ( bytes ) {
54+ if ( bytes == null ) return '-' ;
55+ const n = Number ( bytes ) ;
56+ if ( ! Number . isFinite ( n ) ) return '-' ;
57+ let kb = n / 1000 ; // 输入单位: B; 最小单位 KB
58+ const units = [ 'KB' , 'MB' , 'GB' , 'TB' , 'PB' ] ;
59+ let i = 0 ;
60+ while ( kb >= 1000 && i < units . length - 1 ) { kb /= 1000 ; i ++ ; }
61+ const out = kb >= 100 ? kb . toFixed ( 0 ) : kb . toFixed ( 1 ) ;
62+ return out + ( units [ i ] || units [ units . length - 1 ] ) ;
63+ }
2664// (清理) pct / clsBy 已不再使用
2765function humanAgo ( ts ) { if ( ! ts ) return '-' ; const s = Math . floor ( ( Date . now ( ) / 1000 - ts ) ) ; const m = Math . floor ( s / 60 ) ; return m > 0 ? m + ' 分钟前' :'几秒前' ; }
2866function num ( v ) { return ( typeof v === 'number' && ! isNaN ( v ) ) ? v : '-' ; }
0 commit comments