svelte-persisted-state
Version:
Svelte 5 persisted states, [svelte-persisted-store](https://github.com/joshnuss/svelte-persisted-store), but implemented with Svelte 5 Runes.
36 lines (35 loc) • 982 B
TypeScript
type Serializer<T> = {
parse: (text: string) => T;
stringify: (object: T) => string;
};
type StorageType = 'local' | 'session' | 'cookie';
interface CookieOptions {
expireDays?: number;
maxAge?: number;
path?: string;
domain?: string;
secure?: boolean;
sameSite?: 'Strict' | 'Lax' | 'None';
httpOnly?: boolean;
}
interface Options<T> {
storage?: StorageType;
serializer?: Serializer<T>;
syncTabs?: boolean;
/** @deprecated Use cookieOptions.expireDays instead */
cookieExpireDays?: number;
cookieOptions?: CookieOptions;
onWriteError?: (error: unknown) => void;
onParseError?: (error: unknown) => void;
beforeRead?: (value: T) => T;
beforeWrite?: (value: T) => T;
}
export declare function persistedState<T>(key: string, initialValue: T, options?: Options<T>): {
/**
* @deprecated Use current to align with Svelte conventions
*/
value: T;
current: T;
reset(): void;
};
export {};