UNPKG

@lesjoursfr/browser-tools

Version:

Some browser tools for events & DOM manipulation.

52 lines (51 loc) 1.99 kB
export declare enum KeyValueStorageTypes { localStorage = 1, cookies = 2 } export declare abstract class AbstractKeyValueStore { readonly type: KeyValueStorageTypes; constructor(type: KeyValueStorageTypes); /** * Return the key's value, or null if the key does not exist. * @param {string} key the name of the key you want to retrieve the value of * @returns {undefined|string } the value of the key or undefined if the key does not exist */ abstract getItem(key: string): undefined | string; /** * Add the key to the store, or update that key's value if it already exists. * @param {string} key the name of the key you want to create/update * @param {string} value the value you want to give the key you are creating/updating */ abstract setItem(key: string, value: string): void; /** * Remove the key from the store if it exists. * @param {string} key the name of the key you want to remove */ abstract removeItem(key: string): void; } export declare class LocalStorageKeyValueStore extends AbstractKeyValueStore { constructor(); getItem(key: string): undefined | string; setItem(key: string, value: string): void; removeItem(key: string): void; } export declare class CookiesKeyValueStore extends AbstractKeyValueStore { private readonly expires; constructor(expires: number); getItem(key: string): undefined | string; setItem(key: string, value: string): void; removeItem(key: string): void; } /** * Check if we can use the localStorage. * @returns {boolean} */ export declare function isLocalStorageAvailable(): boolean; /** * Get the default store for the browser. * The default store is the localStorage if it's available or the cookies. * * @param {number} expires the expires value for the cookies * @returns {AbstractKeyValueStore} the default store */ export declare function getDefaultKeyValueStore(expires?: number): AbstractKeyValueStore;