@sophat/sessions
Version:
A TypeScript utility library for managing browser session storage with a simple API. Provides methods to set, get, update, remove, and clear session storage items, plus key enumeration. Ideal for client-side state management and data persistence in web ap
47 lines (46 loc) • 1.82 kB
TypeScript
/**
* Provides a set of utility functions for interacting with the browser's session storage.
*/
export declare class Sessions {
/**
* Sets a key-value pair in the session storage.
* @param key - The key to store the value under.
* @param value - The value to store.
* @returns `true` if the item was successfully set, `false` otherwise.
*/
static setItem: (key: string, value: any) => boolean;
/**
* Retrieves the value stored in the session storage under the specified key.
* @param key - The key to retrieve the value for.
* @returns The value stored under the specified key, or `null` if the key does not exist or an error occurs.
*/
static getItem: (key: string) => any;
/**
* Updates the value stored in the session storage under the specified key.
* @param key - The key to update the value for.
* @param value - The new value to store.
* @returns `true` if the item was successfully updated, `false` otherwise.
*/
static updateItem: (key: string, value: any) => boolean;
/**
* Removes the item stored in the session storage under the specified key.
* @param key - The key of the item to remove.
* @returns `true` if the item was successfully removed, `false` otherwise.
*/
static removeItem: (key: string) => boolean;
/**
* Clears all items stored in the session storage.
* @returns `true` if the session storage was successfully cleared, `false` otherwise.
*/
static clear: () => boolean;
/**
* Gets an array of all the keys stored in the session storage.
* @returns An array of all the keys stored in the session storage.
*/
static getKeys: () => string[];
}
declare global {
interface Window {
Sessions: typeof Sessions;
}
}