Skip to content

Instantly share code, notes, and snippets.

@basecss
Created January 26, 2014 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save basecss/8631473 to your computer and use it in GitHub Desktop.
Save basecss/8631473 to your computer and use it in GitHub Desktop.
check localStorageSpace
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