-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
master1lan
committed
Jan 15, 2023
1 parent
06ea688
commit ad23a08
Showing
6 changed files
with
108 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,31 @@ | ||
| export function getLocalStorage<T>(searchName: string, defaultRes: T): T { | ||
| if (!localStorage) { | ||
| return defaultRes; | ||
| export class Storage<T> { | ||
| itemName: string; | ||
| constructor(itemName: string) { | ||
| this.itemName = itemName; | ||
| } | ||
| if (!localStorage.getItem(searchName)) { | ||
| localStorage.setItem(searchName, JSON.stringify(defaultRes)); | ||
| private getStorage(Storagename: globalThis.Storage, defaultRes: T): T { | ||
| if (!Storagename) { | ||
| return Storagename; | ||
| } | ||
| if (!Storagename.getItem(this.itemName)) { | ||
| Storagename.setItem(this.itemName, JSON.stringify(defaultRes)); | ||
| } | ||
| return JSON.parse(Storagename.getItem(this.itemName) as string); | ||
| } | ||
| private setStorage(Storagename: globalThis.Storage, targetRes: T): void { | ||
| if (Storagename) | ||
| Storagename.setItem(this.itemName, JSON.stringify(targetRes)); | ||
| } | ||
| getLocalStorage(defaultRes: T): T { | ||
| return this.getStorage(localStorage, defaultRes); | ||
| } | ||
| getSessionStorage(defaultRes: T): T { | ||
| return this.getStorage(sessionStorage, defaultRes); | ||
| } | ||
| setLocalstorage(targetRes: T): void { | ||
| this.setStorage(localStorage, targetRes); | ||
| } | ||
| setSessionStorage(targetRes: T): void { | ||
| this.setStorage(sessionStorage, targetRes); | ||
| } | ||
| return JSON.parse(localStorage.getItem(searchName) as string); | ||
| } | ||
| export function setLocalstorage(itemName: string, targetRes: unknown): void { | ||
| if (localStorage) localStorage.setItem(itemName, JSON.stringify(targetRes)); | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| /// <reference types="vite/client" /> | ||
| declare const __APP_VERSION__: string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters