web-localstorage-plus
Version:
Enhanced localStorage
142 lines (128 loc) • 4.54 kB
TypeScript
type PluginParams = {
key: string;
value: any;
namespace: string | undefined;
expireTime: string | undefined;
encrypt: string | undefined;
wark: "getItem" | "setItem" | "removeItem" | "clear";
ctx: Omit<This, 'plugin'>;
};
interface GetParams {
key: string;
namespace?: string;
}
interface SetParams {
key: string;
value: any;
namespace?: string;
}
interface RemoveParams {
key: string;
namespace?: string;
}
declare function export_default$1(rootName: string): {
load: () => any;
methods: {
getItem(params: GetParams): any;
setItem(params: SetParams): void;
removeItem(params: RemoveParams): void;
removeSpace(space: string): void;
clear(): void;
};
};
declare function export_default(rootName: string): {
getItem: typeof getItem;
setItem: typeof setItem;
removeItem: typeof removeItem;
clear: typeof clear;
onChange: typeof change;
onExpire: typeof expire;
postMessage: {
(key: string, payload: any): void;
(key: string, payload: any, mode: "__OFFLINE_MODE__"): void;
};
onMessage: {
(key: string, callback: (payload: any) => void, overwrite?: boolean | undefined): void;
(key: string, callback: (payload: any) => void, mode?: "__OFFLINE_MODE__" | undefined): void;
};
use: typeof use;
};
type Storage = ReturnType<typeof export_default>;
interface Init {
(config?: {
rootName?: string;
noUseLocalStorage?: boolean;
}): Storage;
created?: boolean;
localStorage?: typeof window.localStorage;
}
declare function getItem(key: string): any;
declare function getItem(key: string, namespace: string): any;
declare function getItem(key: string[]): any;
declare function getItem(key: string[], namespace: string): any;
declare function getItem(key: string[], isFlatten: boolean): any;
declare function getItem(key: string[], namespace?: string, isFlatten?: boolean): any;
declare function getItem(key: GetParams[], isFlatten?: boolean): any;
declare function getItem(key: (GetParams | string)[], isFlatten?: boolean): any;
type Params = SetParams & {
encrypt?: boolean;
expireTime?: any;
};
declare function setItem(key: string, value: any): void;
declare function setItem(key: string, value: any, namespace: string): void;
declare function setItem(key: string, value: any, encrypt: boolean): void;
declare function setItem(key: string, value: any, expireTime: number): void;
declare function setItem(key: string, value: any, namespace?: string, expireTime?: number, encrypt?: boolean): void;
declare function setItem(key: Params[], namespace?: string): void;
declare function removeItem(key: string): void;
declare function removeItem(key: string, namespace: string): void;
declare function removeItem(key: string[]): void;
declare function removeItem(key: RemoveParams[]): void;
declare function clear(include?: string[], reverse?: boolean): void;
type Callback$1 = (p: {
oldValue: any;
newValue: any;
key: string;
namespace?: string;
}) => void;
declare function change(key: string, callback: Callback$1): void;
declare function change(key: string, callback: Callback$1, namespace?: string): void;
type Callback = (p: {
name: string;
namespace: string;
}) => void;
declare function expire(key: string, callback: Callback): void;
declare function expire(key: string, callback: Callback, namespace?: string): void;
type PluginCb = (params: PluginParams) => any;
type Plugin = {
framework: "buildIn" | "customer";
apis: {
getItem: PluginCb;
setItem: PluginCb;
removeItem: PluginCb;
clear: PluginCb;
};
};
type This = ReturnType<typeof export_default$1> & {
plugins: Plugin[];
};
declare function use(userCallback: PluginCb, framework?: "customer" | "buildIn"): void;
declare function useStorage(): {
getItem: typeof getItem;
setItem: typeof setItem;
removeItem: typeof removeItem;
clear: typeof clear;
onChange: typeof change;
onExpire: typeof expire;
postMessage: {
(key: string, payload: any): void;
(key: string, payload: any, mode: "__OFFLINE_MODE__"): void;
};
onMessage: {
(key: string, callback: (payload: any) => void, overwrite?: boolean | undefined): void;
(key: string, callback: (payload: any) => void, mode?: "__OFFLINE_MODE__" | undefined): void;
};
use: typeof use;
};
declare const _default: Init;
export { _default as default, useStorage };