|
| 1 | +/** |
| 2 | + * A memory-backed implementation of the Web Storage API. |
| 3 | + * |
| 4 | + * @see https://github.com/download/memorystorage |
| 5 | + */ |
| 6 | + |
| 7 | +interface MemoryStorage { |
| 8 | + /** The identifier for this storage instance. */ |
| 9 | + readonly id: string; |
| 10 | + |
| 11 | + /** The number of key/value pairs currently present in the storage. */ |
| 12 | + readonly length: number; |
| 13 | + |
| 14 | + /** |
| 15 | + * Returns the value associated with the given key, or `null` if the key does not exist. |
| 16 | + * @param key The name of the key to retrieve the value of. |
| 17 | + */ |
| 18 | + getItem(key: string): string | null; |
| 19 | + |
| 20 | + /** |
| 21 | + * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously. |
| 22 | + * @param key The name of the key to create/update. |
| 23 | + * @param value The value to set. |
| 24 | + */ |
| 25 | + setItem(key: string, value: string): void; |
| 26 | + |
| 27 | + /** |
| 28 | + * Removes the key/value pair with the given key, if a key/value pair with the given key exists. |
| 29 | + * @param key The name of the key to remove. |
| 30 | + */ |
| 31 | + removeItem(key: string): void; |
| 32 | + |
| 33 | + /** |
| 34 | + * Returns the name of the nth key, or `null` if n is greater than or equal to the number of key/value pairs. |
| 35 | + * @param index The index of the key to return. |
| 36 | + */ |
| 37 | + key(index: number): string | null; |
| 38 | + |
| 39 | + /** |
| 40 | + * Removes all key/value pairs, if there are any. |
| 41 | + */ |
| 42 | + clear(): void; |
| 43 | + |
| 44 | + /** Index signature to allow accessing stored items as properties. */ |
| 45 | + [key: string]: any; |
| 46 | +} |
| 47 | + |
| 48 | +interface MemoryStorageConstructor { |
| 49 | + /** |
| 50 | + * Creates a new MemoryStorage object implementing the Web Storage API using memory. |
| 51 | + * |
| 52 | + * If no arguments are given, the created memory storage object will read from and write to the |
| 53 | + * `global` memory storage. If a string argument is given, the new storage object will read from |
| 54 | + * and write to its own segment of memory. |
| 55 | + * |
| 56 | + * Can be called with or without `new`. |
| 57 | + * |
| 58 | + * @param id Optional string argument used to isolate this memory storage object from others. |
| 59 | + */ |
| 60 | + new(id?: string): MemoryStorage; |
| 61 | + (id?: string): MemoryStorage; |
| 62 | +} |
| 63 | + |
| 64 | +declare const MemoryStorage: MemoryStorageConstructor; |
| 65 | + |
| 66 | +export = MemoryStorage; |
0 commit comments