Skip to content

The only cookie manager you need for your JS applications, for only 330 bytes.

License

Notifications You must be signed in to change notification settings

mjanssen/koekie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

The only cookie manager you need for your JS applications, for only 330 bytes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published