UNPKG
gaga-js-utils
Version:
latest (1.0.0)
1.0.0
js tools
gaga-js-utils
/
src
/
formatSize
/
index.js
10 lines
•
279 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
// 文件大小格式化
exports
.
formatSize
=
(
size
) =>
{
const
unitsHash =
'B,KB,MB,GB'
.
split
(
','
)
let
index =
0
while
(size >
1024
&& index < unitsHash.
length
) { size /=
1024
index++ }
return
Math
.
round
(size *
100
) /
100
+ unitsHash[index] }