feat(storageSize): created sm.getSize() that returns the size of the localStorage JSON file.

This commit is contained in:
Guz
2022-02-05 17:57:02 -03:00
parent 93fd76e803
commit 7e6869d741
3 changed files with 13 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "ToToday",
"version": "0.7.4",
"version": "0.8.0",
"private": true,
"scripts": {
"dev": "nuxt",

View File

@@ -3,8 +3,9 @@
<p>
<span class="debugInfo">
Version: {{ version }} - Updated: {{ storage_updated }} -
{{ storage_size }}
<br />
</span>
<br />
(c) 2022
<a
href="https://github.com/LoredDev"
@@ -44,6 +45,7 @@ export default Vue.extend({
sm.get('date.updated', true).hour.readable
}`
: '',
storage_size: `${sm.getSize().toFixed(2)}Kb`,
};
},
mounted() {
@@ -53,6 +55,7 @@ export default Vue.extend({
sm.get('date.updated', true).hour.readable
}`
: '';
this.storage_size = `${sm.getSize().toFixed(2)}Kb`;
});
},
});

View File

@@ -97,6 +97,14 @@ const sm = {
if (getOld) return oldValue;
},
/**
* Returns the size of the localStorage in KB
*/
getSize: () => {
const size = new TextEncoder().encode(JSON.stringify(sm.getJSON())).length;
return size / 1024;
},
/**
* Gets and parses the local storage JSON file.
*