UNPKG

@secure-storage/common

Version:

NPM package for storing and managing data across window local-storage and session-storage securely

44 lines (40 loc) 1.38 kB
type SupportedTypes = boolean | object | null | undefined | string | number | bigint; declare const storeTypes: readonly ["local", "session"]; type StoreType = (typeof storeTypes)[number]; declare class Store<S extends StoreType> { private store; private storage; constructor(store?: S); /** * @description Stores data to store matching `key` */ setItem: (key: string, data: SupportedTypes) => void; /** * @description Gets data from store matching `key` */ getItem: <T extends any = SupportedTypes>(key: string) => T | null; /** * @description Removes single item from store matching `key` */ removeItem: (key: string) => void; /** * @description Syncronously removes matched values with matching `prefix` */ clear: () => void; /** * @description Executes `storage.clear()` to clear complete store */ forceClear: () => void; } type Config = { /** @description The secret hash will be used for AES encryption */ secret: string; /** * @description The prefix which will prepend on every key in the storage as `{prefix}.{key}` */ prefix: string; }; declare const configure: (config?: Partial<Config>) => void; declare const localStorage: Store<"local">; declare const sessionStorage: Store<"session">; export { configure, localStorage, sessionStorage };