Started a general utils file

This commit is contained in:
2019-06-02 00:33:49 +02:00
parent 16b967a704
commit 3d97e5d196

11
src/utils.js Normal file
View File

@@ -0,0 +1,11 @@
function sortableSize(string) {
const UNITS = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const [numStr, unit] = string.split(' ');
if (UNITS.indexOf(unit) === -1)
return string
const exponent = UNITS.indexOf(unit) * 3
return numStr * (Math.pow(10, exponent))
}
export { sortableSize }