UNPKG

@jedmao/storage

Version:

A Storage class that implements the Storage interface of the Web Storage API.

51 lines (50 loc) 1.7 kB
import type { _Storage } from './types'; /** * Allows the addition, modification, or deletion of stored data items. */ export declare class Storage implements _Storage { private storage; /** * Returns an integer representing the number of data items stored in the * `Storage` object. */ get length(): number; /** * When invoked, will empty all keys out of the storage. */ clear(): void; /** * When passed a key name, will return that key's value. * @returns the value of the key or `null` if the key does not exist. */ getItem(keyName: string): string | null; /** * When passed a number `index`, this method will return the name of the * nth key in the storage. * @returns the value of the key or `null` if the key does not exist. */ key( /** * The number of the key for which you want the name. This is * a zero-based value. */ index: number): string; /** * When passed a key name, will remove that key from the storage. */ removeItem(keyName: string): void; /** * When passed a key name and value, will add that key to the storage, * or update that key's value if it already exists. * @throws if the storage is full. Particularly, in Mobile Safari * (Safari sets the quota to `0` bytes in private mode, unlike other browsers, * which allow storage in private mode using separate data containers.) * Hence developers should make sure to **always** catch possible exceptions * from `setItem()`**. */ setItem(keyName: string, /** * The value is converted into a string. */ value: string): void; }