Readplace

js-cookie

npm 6 min read
View original
Summary (TL;DR)
js-cookie is a lightweight JavaScript API for handling cookies client-side, under 800 bytes gzipped. It supports ES and AMD/CommonJS modules, is RFC 6265 compliant, and allows custom encoding/decoding. Key methods: Cookies.set(name, value, attributes) to create cookies, Cookies.get(name) to read, and Cookies.remove(name) to delete. Attributes include expires (number of days or Date), path (default '/'), domain, secure, partitioned, and sameSite. Use Cookies.withAttributes() to set global defaults, and Cookies.withConverter() to override encoding/decoding. Delete cookies must use same attributes as when set. Note: path attribute may affect IE cookie retrieval. npm package provides ES and UMD modules.