space() {
        const maxSpace = 5 * 1024 * 1024; // 5MB => 5242880 Bytes
        let usedSpace = 0; // 0 Bytes
        let freeSpaceInProcent;
        let freeSpaceInMB;
        let usedSpaceInMB;
        let usedSpaceInProcent;

        function format(float) {
            return parseFloat(Number(float).toFixed(6))
        }

        for (let name in localStorage) {
            if (!localStorage.hasOwnProperty(name)) {
                continue;
            }
            let size = (localStorage[name].length + name.length) * 2;
            usedSpace += size;
        }

        usedSpaceInProcent = format((usedSpace / maxSpace * 100));
        usedSpaceInMB = format(usedSpace / 1024 / 1024);

        freeSpaceInProcent = format(100 - usedSpaceInProcent);
        freeSpaceInMB = format((maxSpace - usedSpace) / 1024 / 1024);

        return {
            free: {
                mb: freeSpaceInMB,
                procent: freeSpaceInProcent
            }, used: {
                mb: usedSpaceInMB,
                procent: usedSpaceInProcent
            }
        };
    }
// Overview about the used and free space at the localStorage
Overview about the used and free space at the localStorage
Overview about the used and free space at the localStorage
space() {
        const maxSpace = 5 * 1024 * 1024; 
        let usedSpace = 0; 
        let freeSpaceInProcent;
        let freeSpaceInMB;
        let usedSpaceInMB;
        let usedSpaceInProcent;
        function format(float) {
            return parseFloat(Number(float).toFixed(6))
        }
        for (let name in localStorage) {
            if (!localStorage.hasOwnProperty(name)) {
                continue;
            }
            let size = (localStorage[name].length + name.length) * 2;
            usedSpace += size;
        }
        usedSpaceInProcent = format((usedSpace / maxSpace * 100));
        usedSpaceInMB = format(usedSpace / 1024 / 1024);
        freeSpaceInProcent = format(100 - usedSpaceInProcent);
        freeSpaceInMB = format((maxSpace - usedSpace) / 1024 / 1024);
        return {
            free: {
                mb: freeSpaceInMB,
                procent: freeSpaceInProcent
            }, used: {
                mb: usedSpaceInMB,
                procent: usedSpaceInProcent
            }
        };
    }
space ( ) { const maxSpace = 5 * 1024 * 1024 ; let usedSpace = 0 ; let freeSpaceInProcent ; let freeSpaceInMB ; let usedSpaceInMB ; let usedSpaceInProcent ; function format ( float ) { return parseFloat ( Number ( float ) . toFixed ( 6 ) ) } for ( let name in localStorage ) { if ( ! localStorage . hasOwnProperty ( name ) ) { continue ; } let size = ( localStorage [ name ] . length + name . length ) * 2 ; usedSpace += size ; } usedSpaceInProcent = format ( ( usedSpace / maxSpace * 100 ) ) ; usedSpaceInMB = format ( usedSpace / 1024 / 1024 ) ; freeSpaceInProcent = format ( 100 - usedSpaceInProcent ) ; freeSpaceInMB = format ( ( maxSpace - usedSpace ) / 1024 / 1024 ) ; return { free : { mb : freeSpaceInMB , procent : freeSpaceInProcent } , used : { mb : usedSpaceInMB , procent : usedSpaceInProcent } } ; }
Overview about the used and free space at the localStorage
Overview about the used and free space at the localStorage
// 5MB => 5242880 Bytes // 0 Bytes