@naturalcycles/js-lib
Version:
Standard library for universal (browser + Node.js) javascript
26 lines (25 loc) • 736 B
TypeScript
/// <reference lib="es2023" preserve="true" />
/// <reference lib="dom" preserve="true" />
import type { StringMap } from './types.js';
/**
* Implements WebStorage API by using in-memory storage.
* Can be useful in SSR environment or unit tests.
*
* This is how localStorage can be mocked in Node:
*
* Object.assign(globalThis, {
* localStorage: new InMemoryWebStorage(),
* })
*
* @experimental
*/
export declare class InMemoryWebStorage implements Storage {
data: StringMap;
constructor(data?: StringMap);
getItem(key: string): string | null;
setItem(key: string, value: string): void;
removeItem(key: string): void;
key(index: number): string | null;
clear(): void;
get length(): number;
}