mirror of
https://github.com/aljazceru/landscape-template.git
synced 2026-01-08 08:54:24 +01:00
25 lines
432 B
TypeScript
25 lines
432 B
TypeScript
|
|
export class StorageService<T = any> {
|
|
key: string;
|
|
|
|
constructor(key: string) {
|
|
this.key = key;
|
|
}
|
|
|
|
set(newValue: T) {
|
|
localStorage.setItem(this.key, JSON.stringify(newValue));
|
|
}
|
|
|
|
get() {
|
|
const str = localStorage.getItem(this.key);
|
|
if (!str)
|
|
return null;
|
|
|
|
return JSON.parse(str) as T;
|
|
}
|
|
|
|
clear() {
|
|
localStorage.removeItem(this.key)
|
|
}
|
|
}
|