import superjson from 'superjson'; /** * @class HyperStorage * @classdesc A lightweight wrapper for localStorage/sessionStorage * with efficient caching and type-preserving serialization. * * @source https://github.com/Khoeckman/HyperStorage */ declare class HyperStorage { #private; /** Version of the library */ static readonly version: string; static readonly superjson: typeof superjson; /** Key name under which the data is stored. */ readonly itemName: string; /** Default value used when the key does not exist in storage. */ readonly defaultValue: T; /** The underlying storage backend (defaults to `window.localStorage`). */ readonly storage: Storage; /** * Creates a new HyperStorage instance. * * @param {string} itemName - The key name under which the data will be stored. * @param {T} [defaultValue] - Default value assigned to the key if it does not exist yet. * @param {Object} [options={}] - Optional configuration parameters. * @param {(value: T) => string} [options.encodeFn] - Optional function to encode stored values. * @param {(value: string) => string} [options.decodeFn] - Optional function to decode stored values. * @param {Storage} [options.storage=window.localStorage] - Optional custom storage backend. * * @throws {TypeError} If `itemName` is not a string. * @throws {TypeError} If `encodeFn` or `decodeFn` are defined but not functions. * @throws {TypeError} If `storage` does not implement the standard Storage API. */ constructor(itemName: string, defaultValue: T, options?: { encodeFn?: (value: T) => string; decodeFn?: (value: string) => T; storage?: Storage; }); /** * Writes a new value to {@link storage}. * * Automatically caches, stringifies and encodes the value. */ set value(value: T); /** * Gets the stored value from cache. */ get value(): T; /** * Updates a single property on the stored object. * * @template {keyof T} K * @param {K} key The property to update. * @param {T[K]} value The new value for the property. * @returns {T} The updated stored value. */ set(key: K, value: T[K]): T; /** * Updates the stored value using a {@link callback}. * * @param {(value: T) => T} callback Receives the current value and must return the new value. * @returns {T} The updated stored value. */ set(callback: (value: T) => T): T; /** * Synchronizes the {@link value stored value} with the value in {@link storage}. * * This is only necessary if the stored value may have been modified without using the {@link value setter} of this class. * Using this function is **not type safe**. * * @param decodeFn a function to decode the value read from `storage`. * @returns {unknown} The return type is `unknown` because data read from `storage` cannot be type-checked or trusted at compile time because it may have been modified externally. */ sync(decodeFn?: (value: string) => T): unknown; /** * Resets {@link value} to {@link defaultValue}. * * Updates both the cache and the underlying {@link Storage}. * * @returns {T} the restored default value. */ reset(): T; /** * Checks whether {@link value} equals {@link defaultValue}. * * Uses reference comparison for objects and strict equality for primitives. * * @returns {boolean} `true` if the current value matches the default, `false` otherwise. */ isDefault(): boolean; } export default HyperStorage;