index.d.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. export interface StoredData {
  2. [key: string]: any;
  3. }
  4. export type Replacer = (key: any, value: any) => string | String[] | number[];
  5. export type Reviver = (key: string, value: any) => any;
  6. export type EachFn = (key: any, data: any) => false | any;
  7. export type TransactFn = (data: any) => any | undefined;
  8. type BaseSet = (key: any, data: any) => any;
  9. type BaseGet = (key: any) => any;
  10. type BaseSetAll = (obj: Object) => StoredData;
  11. type BaseGetAll = () => StoredData;
  12. type BaseTransact = (fn: EachFn, value?: any) => StoredData;
  13. type BaseClear = (clear: false) => StoreBase;
  14. export type Base = BaseSet & BaseGet & BaseSetAll & BaseGetAll & BaseTransact & BaseClear;
  15. export interface StoreAPI {
  16. clear(): StoreBase;
  17. clearAll(): StoreBase;
  18. each(callback: EachFn): StoreBase;
  19. get(key: any, alt?: any|Reviver): any;
  20. getAll(fillObj?: StoredData): StoredData;
  21. has(key: any): boolean;
  22. isFake(force?: boolean): boolean;
  23. keys(fillList?: string[]): string[];
  24. namespace(namespace: string, singleArea?: true, delim?: string): StoreType;
  25. remove(key: any, alt?: any|Reviver): any;
  26. set(key: any, data: any, overwrite?: boolean|Replacer): any;
  27. setAll(data: Object, overwrite?: boolean|Replacer): StoredData;
  28. add(key: any, data: any): any;
  29. size(): number;
  30. transact(key: any, fn: TransactFn, alt?: any|Reviver): StoreBase;
  31. area(id: string, area: Storage): StoreBase
  32. }
  33. export type StoreBase = StoreAPI & Base;
  34. // these are not guaranteed to be stable across minor versions
  35. // but historically, they have been pretty much so
  36. export interface DeveloperTools {
  37. readonly version: string;
  38. readonly areas: { [name: string]: Storage };
  39. readonly apis: { [name: string]: StoreAPI };
  40. nsdelim: string;
  41. revive: Reviver;
  42. replace: Replacer;
  43. readonly fn: (name: string, fn: Function) => void;
  44. storeAPI: StoreAPI;
  45. get: (area: Storage, key: string) => string;
  46. set: (area: Storage, key: string, string: string) => void;
  47. remove: (area: Storage, key: string) => void;
  48. key: (area: Storage, i: number) => string;
  49. length: (area: Storage) => number;
  50. clear: (area: Storage) => void;
  51. parse: (s: string, fn?: Reviver) => any;
  52. stringify: (d: any, fn?: Replacer) => string;
  53. inherit: (api: StoreAPI, o: object) => object;
  54. }
  55. export type StoreType = StoreBase & {
  56. local: StoreBase;
  57. session: StoreBase;
  58. page: StoreBase;
  59. readonly _: DeveloperTools,
  60. };
  61. declare const store: StoreType
  62. export default store