UNPKG

gm-storage

Version:

An ES6 Map wrapper for the synchronous userscript storage API

34 lines (33 loc) 1.3 kB
export type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue; }; export type Callback<K extends JSONValue, V extends JSONValue, U> = (this: U | undefined, value: V, key: K, store: GMStorageBase<K, V>) => void; export interface Options { strict?: boolean; } export declare const OPTIONS: { strict: boolean; }; declare abstract class GMStorageBase<K extends JSONValue = JSONValue, V extends JSONValue = JSONValue> implements Map<K, V> { constructor(options?: Options); protected abstract parse: (value: string) => K; protected abstract stringify: (value: K) => string; private _has; clear(): void; delete(key: K): boolean; entries(): Generator<[K, V]>; forEach<U>(callback: Callback<K, V, U>, $this: U): void; forEach(callback: Callback<K, V, undefined>): void; get(key: K): V | undefined; get<D>(key: K, $default: D): V | D; has(key: K): boolean; keys(): Generator<K>; set(key: K, value: V): this; setAll(values?: Iterable<[K, V]>): this; get size(): number; values(): Generator<V>; } interface GMStorageBase<K extends JSONValue = JSONValue, V extends JSONValue = JSONValue> extends Map<K, V> { [Symbol.iterator]: GMStorageBase<K, V>['entries']; } export { GMStorageBase };