webdev-power-kit
Version:
A powerful toolkit that simplifies access to browser features like clipboard, notifications, battery, vibration, and more — perfect for modern web developers.
45 lines (44 loc) • 1.42 kB
TypeScript
/**
* @fileoverview A utility to interact safely with localStorage and sessionStorage
* with built-in error handling and JSON support.
*/
type StorageType = 'local' | 'session';
/**
* Sets a value in storage.
* @param key - Storage key
* @param value - Any serializable value
* @param type - 'local' (default) or 'session'
*/
export declare function setItem<T>(key: string, value: T, type?: StorageType): void;
/**
* Gets a value from storage.
* @param key - Storage key
* @param type - 'local' (default) or 'session'
* @returns Parsed value or null
*/
export declare function getItem<T>(key: string, type?: StorageType): T | null;
/**
* Removes a key from storage.
* @param key - Key to remove
* @param type - 'local' (default) or 'session'
*/
export declare function removeItem(key: string, type?: StorageType): void;
/**
* Clears all storage keys.
* @param type - 'local' (default) or 'session'
*/
export declare function clearStorage(type?: StorageType): void;
/**
* Checks if a key exists in storage.
* @param key - Key to check
* @param type - 'local' (default) or 'session'
* @returns true if exists, false otherwise
*/
export declare function hasItem(key: string, type?: StorageType): boolean;
/**
* Returns all keys in storage.
* @param type - 'local' (default) or 'session'
* @returns Array of keys
*/
export declare function getAllKeys(type?: StorageType): string[];
export {};