Skip to content

Instantly share code, notes, and snippets.

@luislobo14rap
Created August 6, 2018 14:02
Show Gist options
  • Select an option

  • Save luislobo14rap/f5c8d1b9e188780813636d68a428aec2 to your computer and use it in GitHub Desktop.

Select an option

Save luislobo14rap/f5c8d1b9e188780813636d68a428aec2 to your computer and use it in GitHub Desktop.
// 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';
};
};
// 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