All files / nexshop-web-contents/src/helpers utility.js

100% Statements 8/8
100% Branches 4/4
100% Functions 1/1
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  59x 4x     55x   55x 55x 58x 58x     55x      
export function convertBytesToKilobytes(bytes) {
    if (!bytes || bytes < 0) {
        return '0B'
    }
 
    const fileUnits = ['B', 'KB', 'MB', 'GB'];
 
    let unitIndex = 0;
    while(bytes >= 1024) {
        bytes = (bytes / 1024).toFixed(1);
        unitIndex++;
    }
 
    return bytes + fileUnits[unitIndex];
}