@osaedasia/oresume
Version:
A user-friendly library for generating complete Single Page Applications (SPAs)
44 lines (43 loc) • 1.59 kB
TypeScript
/**
* A utility class for managing persistent storage of data in the browser's localStorage.
* Provides type-safe methods to save, retrieve, and remove key-value pairs.
* @template T The type of data being stored.
*/
export declare class Store<T> {
/**
* The unique identifier used to store and retrieve data from localStorage.
*/
private readonly _key;
/**
* Creates a new Store instance.
* @param {string} key The unique identifier for storing data.
* @param {T} data The initial data to be stored.
* @throws {Error} If the provided key is empty or contains only whitespace.
*/
constructor(key: string, data: T);
/**
* Creates a new Store instance from existing localStorage data.
* @param {string} key The key to lookup in localStorage.
* @returns {Store<T> | null} A new Store instance if data exists, null otherwise.
*/
static fromKey<T>(key: string): Store<T> | null;
/**
* @returns {T} The stored data associated with this instance's key.
* @throws {StorageDataNotFoundError} If no data exists for the current key.
*/
getData(): T;
/**
* @param {T} data - The data to persist in localStorage.
*/
save(data: T): void;
/**
* Removes the stored data associated with this instance's key.
*/
remove(): void;
/**
* Validates that a key is non-empty and contains non-whitespace characters.
* @param {string} key The key to validate.
* @throws {InvalidStorageKeyError} If the key is invalid.
*/
private _assertKeyIsValid;
}