From 3d97e5d19658f7655c983e13adf4ec92446b9e4f Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 2 Jun 2019 00:33:49 +0200 Subject: [PATCH] Started a general utils file --- src/utils.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/utils.js diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000..4650f07 --- /dev/null +++ b/src/utils.js @@ -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 } \ No newline at end of file