move fileSize to ui-components so it available for plugins

This commit is contained in:
Eduard Heimbuch
2019-09-05 07:59:15 +02:00
parent c5a90963ba
commit 231d4d8810
5 changed files with 3 additions and 4 deletions

View File

@@ -0,0 +1,27 @@
// @flow
import React from "react";
type Props = {
bytes: number
};
class FileSize extends React.Component<Props> {
static format(bytes: number) {
if (!bytes) {
return "0 B";
}
const units = ["B", "K", "M", "G", "T", "P", "E", "Z", "Y"];
const i = Math.floor(Math.log(bytes) / Math.log(1024));
const size = i === 0 ? bytes : (bytes / 1024 ** i).toFixed(2);
return `${size} ${units[i]}`;
}
render() {
const formattedBytes = FileSize.format(this.props.bytes);
return <span>{formattedBytes}</span>;
}
}
export default FileSize;