function processInput(inputValue: number | string | null) { if (inputValue == null || Number.isNaN(inputValue)) { return null; } return Number(inputValue); } export function fData(inputValue: number | string | null) { const number = processInput(inputValue); if (number === null || number === 0) { return '0 bytes'; } const units = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; const decimal = 2; const baseValue = 1024; const index = Math.floor(Math.log(number) / Math.log(baseValue)); const fm = `${parseFloat((number / baseValue ** index).toFixed(decimal))} ${units[index]}`; return fm; }