release v2.0.0 #4

Merged
crimsen merged 481 commits from develop into master 2024-01-18 15:15:08 +00:00
2 changed files with 36 additions and 0 deletions
Showing only changes of commit 6769e18ffa - Show all commits

View File

@ -4,5 +4,6 @@ export * from './src/stores/';
export * from './src/utils/datetime'; export * from './src/utils/datetime';
export * from './src/utils/permission'; export * from './src/utils/permission';
export * from './src/utils/persistent';
export * from './src/utils/validators'; export * from './src/utils/validators';
export * from './src/utils/misc'; export * from './src/utils/misc';

View File

@ -0,0 +1,35 @@
import { LocalStorage, Platform } from 'quasar';
import { Storage } from '@capacitor/storage';
type GetReturn = Date | number | boolean | string | object;
export class PersistentStorage {
static clear() {
if (Platform.is.capacitor) return Storage.clear();
else return Promise.resolve(LocalStorage.clear());
}
static remove(key: string) {
if (Platform.is.capacitor) return Storage.remove({ key: key });
else return Promise.resolve(LocalStorage.remove(key));
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
static set(key: string, value: any) {
if (Platform.is.capacitor) return Storage.set({ key, value: JSON.stringify(value) });
else return Promise.resolve(LocalStorage.set(key, value));
}
static get<T extends GetReturn>(key: string) {
if (Platform.is.capacitor)
return Storage.get({ key }).then((v) =>
v.value === null ? null : (JSON.parse(v.value) as T)
);
else return Promise.resolve(LocalStorage.getItem<T>(key));
}
static keys() {
if (Platform.is.capacitor) return Storage.keys().then((v) => v.keys);
else return Promise.resolve(LocalStorage.getAllKeys());
}
}