Skip to content

Instantly share code, notes, and snippets.

@hugomaiavieira
Last active December 21, 2015 21:08
Show Gist options
  • Save hugomaiavieira/6365838 to your computer and use it in GitHub Desktop.
Save hugomaiavieira/6365838 to your computer and use it in GitHub Desktop.
Script para verificar o espaço utilizado no localStorage
// based on: http://stackoverflow.com/a/17887889/529418
// On Android I get the max 2.5M characters in localStorage (Strings in JavaScript are UTF-16).
var localStorageUsedSpace = function(){
var allStrings = '';
for(var key in window.localStorage){
if(window.localStorage.hasOwnProperty(key)){
allStrings += window.localStorage[key];
}
}
return allStrings ? 3 + ((allStrings.length*16)/(8*1024)) + ' KB' : 'Empty (0 KB)';
};
var localStorageUsedSpaceBy = function(name){
var allStrings = '';
for(var key in window.localStorage){
if(window.localStorage.hasOwnProperty(key)){
if (key.indexOf(name) === 0)
allStrings += window.localStorage[key];
}
}
return allStrings ? 3 + ((allStrings.length*16)/(8*1024)) + ' KB' : 'Empty (0 KB)';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment