UNPKG

reactive-localstorage

Version:
73 lines (72 loc) 2.69 kB
declare const $injectMark: unique symbol; declare const $handlers: unique symbol; export declare class LocalStorage implements Storage { readonly supported: boolean; readonly native: Storage; protected _events: { [P in keyof ReactiveLocalStorageEventMap]?: Set<ReactiveLocalStorageEventMap[P]>; }; protected _cache: Map<string, string | null>; protected _length: number; protected _injected: boolean; constructor(window?: Window, storage?: Storage); get version(): string; get length(): number; key(index: number): string | null; getItem(key: string): string | null; setItem(key: string, value: string): void; removeItem(key: string): void; clear(): void; on<K extends keyof ReactiveLocalStorageEventMap>(name: K, fn: ReactiveLocalStorageEventMap[K]): void; off<K extends keyof ReactiveLocalStorageEventMap>(name: K, fn: ReactiveLocalStorageEventMap[K]): void; feed(key: string | null, newValue: string | null, oldValue: string | null): void; protected set(key: string, value: string | null): void; protected emit<K extends keyof ReactiveLocalStorageEventMap>(name: K, ...args: ArgumentsType<ReactiveLocalStorageEventMap[K]>): void; protected inject(): void; } export interface ReactiveLocalStorageEventMap { change(key: string | null, newValue: string | null, oldValue: string | null): void; } interface Handler { injector: LocalStorage; getItem?(this: Storage, key: string, value: string | null): void; setItem?(this: Storage, key: string, value: string): void; removeItem?(this: Storage, key: string): void; clear?(this: Storage): void; } declare var Storage: { prototype: Storage; new (): Storage; }; interface Storage { [$injectMark]?: boolean; [$handlers]?: Handler[]; /** * Returns the number of key/value pairs currently present in the list associated with the * object. */ readonly length: number; /** * Empties the list associated with the object of all key/value pairs, if there are any. */ clear(this: Storage): void; /** * value = storage[key] */ getItem(this: Storage, key: string): string | null; /** * Returns the name of the nth key in the list, or null if n is greater * than or equal to the number of key/value pairs in the object. */ key(index: number): string | null; /** * delete storage[key] */ removeItem(this: Storage, key: string): void; /** * storage[key] = value */ setItem(this: Storage, key: string, value: string): void; } declare type ArgumentsType<T> = T extends (...args: infer A) => any ? A : []; export {};