UNPKG

quantique-converter

Version:
21 lines (16 loc) 578 B
// Convert to bytes const convertToBytes = (fileSize, parameters) => { const units = { KB: 1024, MB: 1024 * 1024, GB: 1024 * 1024 * 1024, TB: 1024 * 1024 * 1024 * 1024, PB: 1024 * 1024 * 1024 * 1024 * 1024, }; if (!units[parameters?.sizeUnit.toUpperCase()]) { return { isValid: false, error: 'Unsupported unit', convertedValue: '' }; } const convertedValue = fileSize * units[parameters?.sizeUnit.toUpperCase()]; return { isValid: true, error: '', convertedValue: convertedValue }; }; module.exports = convertToBytes;