Releases: Bluzzi/cookie-muncher
Releases · Bluzzi/cookie-muncher
V0.4.0
🚀 What's New
- The documentation has been greatly improved, with lots of references to RFC 6265 specifications and relevant details
- The function
domCookie.setCookie()now checks if there are already more than 50 cookies and if the cookie is longer than 4096 bytes (see the limitations of RFC 6265) - The
domCookie.removeCookie()function now takes anoptionsargument to be able to remove cookies on specific path or domain - An error will now be thrown if
navigator.cookieEnabledisfalsewhen using thedomCookiefunctions - The serialization of a cookie now encodes (with
encodeURIComponent()) its value as well as the path and domain parameters if they are specified
V0.3.0
V0.2.0
🚀 What's New
domCookiefor manage cookies from browser DOMdomCookie.set(cookie: Cookie, options?: CookieOptions): voiddomCookie.get(name: string): Cookie | nulldomCookie.getAll(): Cookie[]domCookie.remove(name: string): void
📦 Changes
serializeCookie(...)function is nowhttpCookie.serialize(...)parseCookies(...)function is nowhttpCookie.parse(...)Pathdefault value is now/forCookieOptions
V0.1.0
📦 Features
serializeCookiefunction to format a string representing a cookie, useful for setting cookies in a HTTP Set-Cookie headerparseCookiesfunction to parse cookies from a string separated with semicolonCookieMaxAgeenum with the most common expiration times
🛠️ Installation
Install the package using one of the following package managers:
- npm:
npm install cookie-muncher - yarn:
yarn add cookie-muncher - pnpm:
pnpm add cookie-muncher
🚀 Example Usage
import type { Cookie } from "cookie-muncher";
import { serializeCookie, parseCookies, CookieMaxAge } from "cookie-muncher";
// Serialize:
const cookie: Cookie = {
name: "myCookie",
value: "myValue",
};
const serializedCookie = serializeCookie(cookie, { maxAge: CookieMaxAge.OneMonth });
console.log(serializedCookie); // "myCookie=myValue; Max-Age=3600"
// Parse:
const cookieString = "myCookie=myValue; myOtherCookie=myOtherValue";
const parsedCookies = parseCookies(cookieString);
console.log(parsedCookies); // [{ name: "myCookie", value: "myValue" }, { name: "myOtherCookie", value: "myOtherValue" }]