CoCookie: Easy Cookies Interface
CoCookie is a minimalistic accurate JavaScript ES6 package that provides a convenient interface to work with cookies.
The API is as simple as possible. The documented code is clean and transparent. See the usage in examples below.
Usage
; // Set cookie "key" to value "bR6o1x"; // Set cookie "key" to value "bR6o1x" with additional attributes; // Get value of cookie "key"let key = ; // Delete cookie "key"; // When cookie is already set, you can just update its without touching its value.; // Delete cookie "key" with optional attributes; // Need the list of cookies to iterate through? Here you go:;;// Note that you cannot delete cookies from other domains/paths in this way.// Do delete the cookie from known path/domain use delete attributes (see delete above). // If you need to store JSON in cookies (which is not common), use the following pattern.;let object = JSON;
Installation
npm install --save-dev cocookie
Install CoCookie as a npm dependency. Use this package with any module bundler like Webpack until ES6 modules standard will be implemented natively.
If your module bundler cannot resolve ES6 code, use import cookie from "cocookie/umd.js";
. For
usage from browser directly use the script tag (or download this script):