Created
January 26, 2014 11:44
-
-
Save basecss/8631473 to your computer and use it in GitHub Desktop.
check localStorageSpace
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
var localStorageSpace = function(){ | |
var data = ''; | |
for(var key in window.localStorage) { | |
if(window.localStorage.hasOwnProperty(key)) { | |
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'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment