Created
August 6, 2018 14:02
-
-
Save luislobo14rap/f5c8d1b9e188780813636d68a428aec2 to your computer and use it in GitHub Desktop.
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
| // localStorageGetSpace.js v1, https://stackoverflow.com/questions/4391575/how-to-find-the-size-of-localstorage | |
| function localStorageGetSpace(number = false) { | |
| let allStrings = ''; | |
| for (let key in window.localStorage) { | |
| if (window.localStorage.hasOwnProperty(key)) { | |
| allStrings += window.localStorage[key]; | |
| }; | |
| }; | |
| allStrings = allStrings ? 3 + ((allStrings.length * 16) / 8192) : 0; | |
| if (number == true) { | |
| return allStrings; | |
| } else if (typeof formatBytes != 'undefined') { | |
| return formatBytes(allStrings); | |
| } else { | |
| return allStrings + ' KB'; | |
| }; | |
| }; |
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
| // localStorageGetSpace.min.js v1 | |
| function localStorageGetSpace(a=!1){let b='';for(let c in window.localStorage)window.localStorage.hasOwnProperty(c)&&(b+=window.localStorage[c]);return b=b?3+16*b.length/8192:0,!0==a?b:'undefined'==typeof formatBytes?b+' KB':formatBytes(b)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment