UNPKG

modern-api.storage

Version:
89 lines (87 loc) 2.44 kB
interface GetOptions { removeStale?: boolean; updateAge?: boolean; } interface SetOptions { ttl?: number | string; } declare class StorageEnhancer { storage: Storage; constructor(storage: Storage); /** * detect whether key is in storage * * @param {string} key * @returns {boolean} */ hasItem(key: string): boolean; /** * detect whether key is still alive * * @param {string} key * @returns {boolean} - return true only if key existed and staled */ staleItem(key: string): boolean; /** * get item via key * * @param {string} key * @param {GetOptions} options * @param {boolean} options.removeStale - whether remove item when key staled * @param {boolean} options.updateAge - whether delay key ttl * @returns {string | null} */ getItem(key: string, { removeStale, updateAge }?: GetOptions): string | null; /** * set item via key * * @param {string} key * @param {string} value * @param {SetOptions} options * @param {number} options.ttl - key's time to live, ms * @returns {void} */ setItem(key: string, value: string, { ttl }?: SetOptions): void; /** * get json via key * * @param {string} key * @param {GetOptions} options * @param {boolean} options.removeStale - whether remove item when key staled * @param {boolean} options.updateAge - whether delay key ttl * @returns {string | object | null} */ getJson(key: string, options?: GetOptions): any; /** * set json via key * * @param {string} key * @param {string} value * @param {SetOptions} options * @param {number} options.ttl - key's time to live, ms * @returns {void} */ setJson(key: string, value: object, options?: SetOptions): void; /** * remove item via key * * @param {string} key * @returns {void} */ removeItem(key: string): void; /** * clear all keys and items * * @returns {void} */ clear(): void; _prependExpire(value: string, ttl?: number | string | null): string; _parseValue(value: string): { value: string; start: string | null; ttl: string | null; }; _isStale(start?: number | string | null, ttl?: number | string | null): boolean; _isNumber(n: any): boolean; } export { StorageEnhancer };