UNPKG

@stacksjs/stx

Version:

A performant UI Framework. Powered by Bun.

70 lines 2 kB
/** * Parse all cookies from document.cookie */ export declare function parseCookies(): Record<string, string>; /** * Get a specific cookie value */ export declare function getCookie(name: string): string | null; /** * Set a cookie */ export declare function setCookie(name: string, value: string, options?: CookieOptions): void; /** * Remove a cookie */ export declare function removeCookie(name: string, options?: Pick<CookieOptions, 'path' | 'domain'>): void; /** * Create a reactive cookie reference * * @example * ```ts * // Simple usage * const token = useCookie<string>('auth_token') * token.value = 'abc123' // Automatically persists * * // With options * const session = useCookie<SessionData>('session', { * maxAge: 60 * 60 * 24 * 7, // 7 days * secure: true, * sameSite: 'strict' * }) * * // Subscribe to changes * token.subscribe((newValue) => console.log('Token changed:', newValue)) * ``` */ export declare function useCookie<T = string>(name: string, options?: CookieOptions): CookieRef<T>; /** * Get all cookies as an object */ export declare function useCookies(): Record<string, string>; /** * Clear all cookies (that are accessible) */ export declare function clearCookies(options?: Pick<CookieOptions, 'path' | 'domain'>): void; /** * useCookie - Reactive cookie composable * * Similar to Nuxt's useCookie but for STX applications. * Provides a reactive, type-safe wrapper around document.cookie. */ export declare interface CookieOptions { maxAge?: number expires?: Date | number | string path?: string domain?: string secure?: boolean httpOnly?: boolean sameSite?: 'strict' | 'lax' | 'none' default?: unknown encode?: (value: string) => string decode?: (value: string) => string } export declare interface CookieRef<T> { value: T | null get: () => T | null set: (value: T, options?: CookieOptions) => void remove: () => void subscribe: (callback: (value: T | null, prev: T | null) => void) => () => void }