koel/resources/assets/js/services/localStorageService.ts

13 lines
386 B
TypeScript
Raw Normal View History

2022-05-14 18:49:45 +00:00
import { get as baseGet, remove as baseRemove, set as baseSet } from 'local-storage'
2022-04-15 14:24:30 +00:00
2022-04-24 08:50:45 +00:00
export const localStorageService = {
2022-05-14 18:49:45 +00:00
get: <T> (key: string, defaultValue: T | null = null): T | null => {
2022-04-15 14:24:30 +00:00
const value = baseGet<T>(key)
return value === null ? defaultValue : value
},
2022-05-14 18:49:45 +00:00
set: (key: string, value: any) => baseSet(key, value),
remove: (key: string) => baseRemove(key)
2022-04-15 14:24:30 +00:00
}