nuxt
Version:
52 lines • 2.04 kB
TypeScript
import { CookieSerializeOptions } from "../types/cookie.js";
import { Ref } from "vue";
//#region src/app/composables/cookie.d.ts
type _CookieOptions = Omit<CookieSerializeOptions, 'encode'>;
export interface CookieOptions<T = any> extends _CookieOptions {
decode?(value: string | null | undefined): T;
encode?(value: T): string;
default?: () => T | Ref<T>;
watch?: boolean | 'shallow';
readonly?: boolean;
/** Whether this ref reads the named cookie from the jar. Defaults to an exact name match. */
filter?(key: string): boolean;
/**
* Refresh cookie expiration even when the value remains unchanged.
*
* By default, a cookie is only rewritten when its value changes.
* When `refresh` is set to `true`, the cookie will be re-written
* on every explicit assignment (e.g. `cookie.value = cookie.value`),
* extending its expiration even if the value is the same.
*
* Note: the expiration is not refreshed automatically — you must
* assign to `cookie.value` to trigger the refresh.
*
* Ignored when `readonly` is set.
*
* @default false
*/
refresh?: boolean;
}
/** Options accepted by `useCookie`. */
export interface UseCookieOptions<T = any> extends Omit<CookieOptions<T>, 'expires'> {
/**
* Expiration date for the cookie, or a getter that returns one.
*
* When a function is provided, it is evaluated on every cookie write
* so the expiration can be refreshed when the value is re-set.
* The getter should be pure (no side effects).
*/
expires?: Date | (() => Date | undefined);
}
export interface CookieRef<T> extends Ref<T> {}
/** @since 3.0.0 */
export declare function useCookie<T = string | null | undefined>(name: string, _opts?: UseCookieOptions<T> & {
readonly?: false;
}): CookieRef<T>;
export declare function useCookie<T = string | null | undefined>(name: string, _opts: UseCookieOptions<T> & {
readonly: true;
}): Readonly<CookieRef<T>>;
/** @since 3.10.0 */
export declare function refreshCookie(name: string): void;
//#endregion
export {};