0.3.0 • Published 3 years ago

@cerebralfart/cookies v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@CerebralFart/Cookies

Simple interaction with cookies in the browser

This library, as the name suggests, allows you to easily interact with cookies in the browser. No longer do you need to parse some complicated URI encoded string, instead, we've collected them already for you. Below we'll quickly go over how you can use this library.

Getting a cookie

const id = Cookie.trackingID;

Setting a cookie

Cookie.trackingID = id;

Removing a cookie

delete Cookie.trackingID;

Checking if a cookie exists

"trackingID" in Cookie;

Enumerating all cookies

for (const name in Cookie) {
  console.log(name);
}

There you have it, that's most there is to this library. If you need some more customization options, do keep reading.

Advanced configuration

It is also possible to customize the options of cookies, but we have provided sane defaults so you will rarely need this.

Cookie.trackingID = new Cookie(id, {
  path: "/subfolder/",
});

The the following options are available:

KeyTypeDefault
pathstring'/'The path for this cookie.
domainstringlocation.hostnameThe domain to which this cookie belongs, check MDN for some implementation notes.
securebooleantrue if the page is served over httpsSet to true if this cookie should only be available in secure contexts.
sameSite'lax','strict' or 'none''lax'The same site behaviour of this cookie.
maxAgenumber14 * 24 * 60 * 60, 14 daysThe maximum age in seconds before this cookie should be removed, mutually exclusive with the expires parameter.
expiresDateThe date this cookie should expire, mutually exclusive with the maxAge parameter.
0.3.0

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago