feat(storageSize): created sm.getSize() that returns the size of the localStorage JSON file.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ToToday",
|
||||
"version": "0.7.4",
|
||||
"version": "0.8.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "nuxt",
|
||||
|
||||
@@ -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`;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user