Created
May 30, 2019 17:04
-
-
Save creesch/0c5d1563f34736eaa30a58a7dcfebde4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function testLocalStorage() { | |
let data = ''; | |
for(var key in window.localStorage) { | |
if(window.localStorage.hasOwnProperty(key)){ | |
data = `${data}${window.localStorage[key]}`; | |
console.log(`${key} = ${((window.localStorage[key].length * 16)/(8 * 1024)).toFixed(2)} KB`); | |
} | |
} | |
console.log(data ? `\n Total space used: ${((data.length * 16)/(8 * 1024)).toFixed(2)} KB` : 'Empty (0 KB)'); | |
console.log(data ? `Approx. space remaining: ${(5120 - ((data.length * 16)/(8 * 1024)).toFixed(2))} KB` : '5 MB'); | |
try { | |
localStorage.setItem('localStorageTestItem', 'localStorageTestItem'); | |
console.log('localStorageTestItem written: ', window.localStorage['localStorageTestItem']) | |
} catch (e) { | |
console.log('localStorage setItem error: ', e); | |
} | |
} | |
testLocalStorage() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment