import { Injectable } from '@angular/core'; import { Storage } from '@ionic/storage'; /* import { Plugins } from '@capacitor/core'; const { Storage } = Plugins; */ @Injectable({ providedIn: 'root' }) export class StorageService { constructor(private storage:Storage,) {} // Store the value async store(key: string, value: any){ const encryptedValue = btoa(escape(JSON.stringify(value))); await this.storage.set(key, encryptedValue); } // Get the value async get(key: string) { const ret = await this.storage.get(key).then((val) => { return val; }); try { return JSON.parse(unescape(atob(ret))); } catch (error) { return unescape(atob(ret)) } } async remove(key: string){ await this.storage.remove(key); } /* // Get the value async get(storageKey: string) { const ret = await Storage.get({ key: storageKey }); return JSON.parse(unescape(atob(ret.value))); } async removeStorageItem(storageKey: string) { await Storage.remove({ key: storageKey }); } // Clear storage async clear() { await Storage.clear(); } */ }