UNPKG

ohayolibs

Version:

Ohayo is a set of essential modules for ohayojp.

30 lines (25 loc) 724 B
import { ITokenModel } from '../token/interface'; import { IStore } from './interface'; export function DA_STORE_TOKEN_LOCAL_FACTORY(): IStore { return new LocalStorageStore(); } /** * `localStorage` storage, **not lost after closing the browser**. * * ```ts * // global-config.module.ts * { provide: DA_STORE_TOKEN, useClass: LocalStorageStore } * ``` */ export class LocalStorageStore implements IStore { get(key: string): ITokenModel { return JSON.parse(localStorage.getItem(key) || '{}') || {}; } set(key: string, value: ITokenModel | null): boolean { localStorage.setItem(key, JSON.stringify(value)); return true; } remove(key: string): void { localStorage.removeItem(key); } }