Last active
December 21, 2015 21:08
-
-
Save hugomaiavieira/6365838 to your computer and use it in GitHub Desktop.
Script para verificar o espaço utilizado no localStorage
This file contains hidden or 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
// 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