1.1.2 • Published 5 years ago

koekie v1.1.2

Weekly downloads
35
License
MIT
Repository
github
Last release
5 years ago

Koekie

npm gzip size

The zero-dependency ~330B cookie manager for your Javascript projects.

Install

npm install --save koekie

Usage

import { setCookie, getCookie, getAllCookies, cookieExists, removeCookie } from 'koekie';

// Set a specific cookie, with a given value.
setCookie(name, value, { expires: 1, in: 'hours', path: '/' });

// Get a specific cookie. Returns false if non-existent
getCookie(name);

// Returns an array with all available cookies
getAllCookies();

// Surprisingly, returns a bool true/false if a cookie exists
cookieExists(name);

// Removes a cookie - Make sure to pass the same path as you used to create it
removeCookie(name, { path: '/' });

Options

You can pass an options parameter to setCookie, which will allow you to control the expiration date for the given cookie. By default, a cookie wil be stored for one hour. The in property accepts four different types; hours, days, months and years (plural!).

When you want to set a cookie for one month, pass { expires: 1, in: 'months' }. This will use the Javascript Date() function to calculate the length and set it for the correct time.

The path option is / by default.

By default, the cookie will be stored for one hour!

Demo

Code demo can be found here

License

MIT

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.8.0

6 years ago

0.7.0

6 years ago

0.6.0

6 years ago