koekie

1.1.2 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i koekie

Weekly Downloads

2

Version

1.1.2

License

MIT

Unpacked Size

30.3 kB

Total Files

17

Last publish

Collaborators

  • mjanssen