When we create a website, we always need to use cookies, either on the browser side, or on the server side through the HTTP headers Cookie and Set-Cookie.
The problem is that most of the packages allowing to handle cookies are not maintained anymore, not written in TS, not exported in both CommonJS and ES module, not 100% compliant with RFC 6265, not complete enough and usable on both server and client side or simply don't have a good API...
That's why I created my own package : Cookie Muncher! A lightweight and typesafe package for manipulating cookies in NodeJS and the browser.
- ๐ Lightweight
- ๐ Works in all browsers
- ๐งช Unit tested
- ๐ท Typesafe
- ๐ฆ Support ESM & CJS
- โ RFC 6265 compliant
- ๐ Well documented
This package is divided into two modules.
httpCookie
Serialize and parse cookie from HTTP headers Cookie and Set-Cookie.
httpCookie.serialize(cookie: Cookie, options?: HttpCookieOptions): stringhttpCookie.parse(cookies: string): Cookie[]HttpCookieOptions
domCookie
Create, update, remove and get cookies from browser DOM.
domCookie.set(cookie: Cookie, options?: DomCookieOptions): voiddomCookie.get(name: string): Cookie | nulldomCookie.getAll(): Cookie[]domCookie.remove(name: string, options?: DomCookieOptions): voidDomCookieOptions
This package will definitely be your best friend the next time you need to use cookies! ๐ช
# NPM
npm install cookie-muncher
# YARN
yarn add cookie-muncher
# PNPM
pnpm install cshookie-muncher
Feel free to drop a โญ on the GitHub repo or contribute! ๐
Top comments (0)