From 332465ad61630d7f1901d4dfb9550f8a8c1fa0b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Fri, 8 Dec 2023 08:18:06 -0300 Subject: [PATCH] refactor: move getFileSizeToClosestByte to root utils --- src/files-and-videos/generic/utils.js | 21 +------------------ src/utils.js | 19 +++++++++++++++++ .../generic => }/utils.test.js | 0 3 files changed, 20 insertions(+), 20 deletions(-) rename src/{files-and-videos/generic => }/utils.test.js (100%) diff --git a/src/files-and-videos/generic/utils.js b/src/files-and-videos/generic/utils.js index 7cbcc07d4c..e23afc7012 100644 --- a/src/files-and-videos/generic/utils.js +++ b/src/files-and-videos/generic/utils.js @@ -1,23 +1,4 @@ -export const getFileSizeToClosestByte = (fileSize, numberOfDivides = 0) => { - if (fileSize > 1000) { - const updatedSize = fileSize / 1000; - const incrementNumberOfDivides = numberOfDivides + 1; - return getFileSizeToClosestByte(updatedSize, incrementNumberOfDivides); - } - const fileSizeFixedDecimal = Number.parseFloat(fileSize).toFixed(2); - switch (numberOfDivides) { - case 1: - return `${fileSizeFixedDecimal} KB`; - case 2: - return `${fileSizeFixedDecimal} MB`; - case 3: - return `${fileSizeFixedDecimal} GB`; - default: - return `${fileSizeFixedDecimal} B`; - } -}; - -export const sortFiles = (files, sortType) => { +export const sortFiles = (files, sortType) => { // eslint-disable-line import/prefer-default-export const [sort, direction] = sortType.split(','); let sortedFiles; if (sort === 'displayName') { diff --git a/src/utils.js b/src/utils.js index 6e5edcee71..47de7412e0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -256,3 +256,22 @@ export const isValidDate = (date) => { return Boolean(formattedValue.length <= 10); }; + +export const getFileSizeToClosestByte = (fileSize, numberOfDivides = 0) => { + if (fileSize > 1000) { + const updatedSize = fileSize / 1000; + const incrementNumberOfDivides = numberOfDivides + 1; + return getFileSizeToClosestByte(updatedSize, incrementNumberOfDivides); + } + const fileSizeFixedDecimal = Number.parseFloat(fileSize).toFixed(2); + switch (numberOfDivides) { + case 1: + return `${fileSizeFixedDecimal} KB`; + case 2: + return `${fileSizeFixedDecimal} MB`; + case 3: + return `${fileSizeFixedDecimal} GB`; + default: + return `${fileSizeFixedDecimal} B`; + } +}; diff --git a/src/files-and-videos/generic/utils.test.js b/src/utils.test.js similarity index 100% rename from src/files-and-videos/generic/utils.test.js rename to src/utils.test.js