版博士V2.0程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

useCookies.d.ts 2.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import * as universal_cookie from 'universal-cookie';
  2. import universal_cookie__default from 'universal-cookie';
  3. import { IncomingMessage } from 'http';
  4. /**
  5. * Creates a new {@link useCookies} function
  6. * @param {Object} req - incoming http request (for SSR)
  7. * @see https://github.com/reactivestack/cookies/tree/master/packages/universal-cookie universal-cookie
  8. * @description Creates universal-cookie instance using request (default is window.document.cookie) and returns {@link useCookies} function with provided universal-cookie instance
  9. */
  10. declare function createCookies(req?: IncomingMessage): (dependencies?: string[] | null, { doNotParse, autoUpdateDependencies }?: {
  11. doNotParse?: boolean | undefined;
  12. autoUpdateDependencies?: boolean | undefined;
  13. }) => {
  14. /**
  15. * Reactive get cookie by name. If **autoUpdateDependencies = true** then it will update watching dependencies
  16. */
  17. get: <T = any>(name: string, options?: universal_cookie.CookieGetOptions | undefined) => T;
  18. /**
  19. * Reactive get all cookies
  20. */
  21. getAll: <T_1 = any>(options?: universal_cookie.CookieGetOptions | undefined) => T_1;
  22. set: (name: string, value: any, options?: universal_cookie.CookieSetOptions | undefined) => void;
  23. remove: (name: string, options?: universal_cookie.CookieSetOptions | undefined) => void;
  24. addChangeListener: (callback: universal_cookie.CookieChangeListener) => void;
  25. removeChangeListener: (callback: universal_cookie.CookieChangeListener) => void;
  26. };
  27. /**
  28. * Reactive methods to work with cookies (use {@link createCookies} method instead if you are using SSR)
  29. * @param {string[]|null|undefined} dependencies - array of watching cookie's names. Pass empty array if don't want to watch cookies changes.
  30. * @param {Object} options
  31. * @param {boolean} options.doNotParse - don't try parse value as JSON
  32. * @param {boolean} options.autoUpdateDependencies - automatically update watching dependencies
  33. * @param {Object} cookies - universal-cookie instance
  34. */
  35. declare function useCookies(dependencies?: string[] | null, { doNotParse, autoUpdateDependencies }?: {
  36. doNotParse?: boolean | undefined;
  37. autoUpdateDependencies?: boolean | undefined;
  38. }, cookies?: universal_cookie__default): {
  39. /**
  40. * Reactive get cookie by name. If **autoUpdateDependencies = true** then it will update watching dependencies
  41. */
  42. get: <T = any>(name: string, options?: universal_cookie.CookieGetOptions | undefined) => T;
  43. /**
  44. * Reactive get all cookies
  45. */
  46. getAll: <T_1 = any>(options?: universal_cookie.CookieGetOptions | undefined) => T_1;
  47. set: (name: string, value: any, options?: universal_cookie.CookieSetOptions | undefined) => void;
  48. remove: (name: string, options?: universal_cookie.CookieSetOptions | undefined) => void;
  49. addChangeListener: (callback: universal_cookie.CookieChangeListener) => void;
  50. removeChangeListener: (callback: universal_cookie.CookieChangeListener) => void;
  51. };
  52. export { createCookies, useCookies };