14 lines
613 B
JavaScript
14 lines
613 B
JavaScript
// 1.bps KB/s or MB/s or GB/s 2.保留两位小数 3.默认是bps
|
|
export var speedConvert = function speedConvert(bps) {
|
|
var contertUnit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 8;
|
|
if (bps === undefined) return "0KB/s";
|
|
var byte = bps / contertUnit;
|
|
if (bps > 1024 * 1024 * 1024) {
|
|
return "".concat((byte / 1024 / 1024 / 1024).toFixed(2), "GB/s");
|
|
} else if (byte > 1024 * 1024) {
|
|
return "".concat((byte / 1024 / 1024).toFixed(2), "MB/s");
|
|
} else if (byte > 1024) {
|
|
return "".concat((byte / 1024).toFixed(2), "KB/s");
|
|
}
|
|
return "".concat(byte, "KB/s");
|
|
}; |