This content originally appeared on DEV Community and was authored by Bluzzi
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): string
httpCookie.parse(cookies: string): Cookie[]
HttpCookieOptions
domCookie
Create, update, remove and get cookies from browser DOM.
domCookie.set(cookie: Cookie, options?: DomCookieOptions): void
domCookie.get(name: string): Cookie | null
domCookie.getAll(): Cookie[]
domCookie.remove(name: string, options?: DomCookieOptions): void
DomCookieOptions
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! 😀
This content originally appeared on DEV Community and was authored by Bluzzi
Bluzzi | Sciencx (2023-04-27T03:14:36+00:00) [JS/TS] Cookie Muncher – Effortless cookie management. Retrieved from https://www.scien.cx/2023/04/27/js-ts-cookie-muncher-effortless-cookie-management/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.