All files / app/codeCharta/ui/customConfigs/addCustomConfigButton/addCustomConfigDialog/downloadAndPurgeConfigs validateLocalStorageSize.ts

87.5% Statements 7/8
100% Branches 0/0
100% Functions 1/1
85.71% Lines 6/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 179x 5x 5x 5x                 5x   5x    
export const validateLocalStorageSize = () => {
    const customLocalStorageLimitInKB = 768
    let allStringsConcatenated = ""
    for (const [key, value] of Object.entries(localStorage)) {
        allStringsConcatenated += key + value
    }
 
    // It does not exist a limit for the total localStorage size that applies to all browsers.
    // Usually 2MB - 10MB are available (5MB seems to be very common).
    // The localStorage size (e.g. 5MB) is assigned per origin.
    // Multiply localStorage characters by 16 (bits because they are stored in UTF-16).
    // Add 3KB as it seems there is some default overhead.
    const localStorageSizeInKB = 3 + (allStringsConcatenated.length * 16) / 8 / 1024
 
    return localStorageSizeInKB <= customLocalStorageLimitInKB
}