Created
August 6, 2015 13:06
-
-
Save jeremypele/4bbd49504b3c45566f95 to your computer and use it in GitHub Desktop.
[Chrome Snippets] LocalStorage Stats
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
// based on answer to question | |
// http://stackoverflow.com/questions/4391575/how-to-find-the-size-of-localstorage | |
(function showLocalStorageSize() { | |
function stringSizeBytes(str) { | |
return str.length * 2; | |
} | |
function toMB(bytes) { | |
return bytes / 1024 / 1024; | |
} | |
function toSize(key) { | |
return { | |
name: key, | |
size: stringSizeBytes(localStorage[key]) | |
}; | |
} | |
function toSizeMB(info) { | |
info.size = toMB(info.size).toFixed(2) + ' MB'; | |
return info; | |
} | |
var sizes = Object.keys(localStorage).map(toSize).map(toSizeMB); | |
console.table(sizes); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment