cookie-facade
v1.0.0
Published
Generic Type wrapper for 'js-cookie'
Maintainers
Readme
cookie-facade
A generic TypeScript wrapper around js-cookie.
Installation
npm install cookie-facadeUsage
import { CookieFacade } from 'cookie-facade';
// Create a facade for a specific cookie type
interface UserPreferences {
theme: 'light' | 'dark';
language: string;
}
const userPrefs = new CookieFacade<UserPreferences>('user_preferences');
// Set a cookie
userPrefs.set({ theme: 'dark', language: 'en' });
// Get a cookie
const prefs = userPrefs.get();
// Remove a cookie
userPrefs.remove();
// With custom cookie options
userPrefs.set(
{ theme: 'dark', language: 'en' },
{ expires: 7, secure: true }
);API
Constructor
new CookieFacade<T>(cookieName: string, defaultOptions?: Cookies.CookieAttributes)Methods
set(value: T, options?: Cookies.CookieAttributes): void- Sets the cookie with the provided valueget(): T | null- Returns the parsed cookie value or null if not foundremove(options?: Cookies.CookieAttributes): void- Removes the cookie
