Easy to use JavaScript/TypeScript library that makes working with cookies on client side less of a pain.
npm i lazycookie
It has same methods as localStorage & sessionStorage
import cookie from "lazycookie";
cookie.getItem("foo") // returns a string which is the value of the provided parameter.
cookie.setItem("foo", "bar", options) // sets item with key of "foo" and value of "bar".
cookie.deleteItem("foo") // deletes item with key of "foo".
cookie.clear() // clears all key/value pairs.
cookie.length // returns the total number of key/value pair.
Name | Value | Description |
---|---|---|
expires | Date | When cookie should expire in Date format. |
maxAge | number | When cookie should expire in millisecond. |