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 anoptions
argument to be able to remove cookies on specific path or domain - An error will now be thrown if
navigator.cookieEnabled
isfalse
when using thedomCookie
functions - 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
domCookie
for manage cookies from browser DOMdomCookie.set(cookie: Cookie, options?: CookieOptions): void
domCookie.get(name: string): Cookie | null
domCookie.getAll(): Cookie[]
domCookie.remove(name: string): void
📦 Changes
serializeCookie(...)
function is nowhttpCookie.serialize(...)
parseCookies(...)
function is nowhttpCookie.parse(...)
Path
default value is now/
forCookieOptions
V0.1.0
📦 Features
serializeCookie
function to format a string representing a cookie, useful for setting cookies in a HTTP Set-Cookie headerparseCookies
function to parse cookies from a string separated with semicolonCookieMaxAge
enum 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" }]