local-store-pro
Version:
Better localStorage, subscribable localStorage, expirable localStorage
64 lines (60 loc) • 2.69 kB
TypeScript
/*! local-store-pro v3.0.3 | MIT */
/**
* NextStorage
* Next localStorage
*/
declare class NextStorage {
namespace: string;
protected store: Storage;
protected observers: Map<any, any>;
protected hasBindWindow: boolean;
protected static storage: NextStorage | null;
static getInstance(): NextStorage;
setHasBindWindow(e: boolean): void;
getHasBindWindow(): boolean;
setNamespace(space: string): void;
getNamespace(): string;
getUsed(): string;
setStore<T extends Storage>(store: T): void;
protected getStore(): Storage;
set(key: string, value: NextStorageValue, expires?: number): this;
get(key: string): NextStorageValue;
getItem(key: string): string | null;
has(key: string): boolean;
publish(observers: StoreListener[] | string, e: StorageEvent, force?: boolean, defaultKey?: string | null): void;
publishAll(e: StorageEvent): void;
subscribe(key: string, listener: StoreListener): this;
getObserver(key: string): StoreListener[];
unsubscribe(keys?: string | string[], listener?: StoreListener): void;
remove(key: string, soft?: boolean): this;
clear(): void;
}
declare type StorageEventKey = string | null;
declare type NextStorageValue = Partial<any> | any[] | null | string | number;
declare type NextStorageEventValue = Partial<any> | any[] | null | string | number;
declare type StoreArgument<T> = [string?, T?, number?];
declare type StoreListener = <T extends StoreProEvent>(e: T) => void;
declare type LocalStoreStageMap = [null, NextStorageValue, NextStorage, NextStorage];
interface StoreProEvent extends Omit<StorageEvent, "newValue" | "oldValue"> {
newValue: NextStorageEventValue;
oldValue: NextStorageEventValue;
native: StorageEvent;
}
interface StoreStage {
localStore: NextStorage;
set: (key: string, value: NextStorageValue, expires?: number) => void;
get: (key: string) => NextStorageValue;
remove: (key: string, soft?: boolean) => void;
has: (key: string) => boolean;
clear: () => void;
subscribe: (key: string, listener: (e: StoreProEvent) => void) => void;
unsubscribe: (keys: string | string[], listener?: (e: StoreProEvent) => void) => void;
getObserver(key: string): StoreListener[];
getUsed: () => string;
}
interface LocalStorePro extends StoreStage {
<T, K extends StoreArgument<T>>(...rest: K): LocalStoreStageMap[K["length"]];
}
declare type LocalStoragePro = NextStorage;
declare const _default: LocalStorePro;
export { LocalStoragePro, LocalStorePro, LocalStoreStageMap, NextStorageEventValue, NextStorageValue, StorageEventKey, StoreArgument, StoreListener, StoreProEvent, _default as default };