cookier
v3.1.0
Published
Simple utility function to get, set and remove cookies
Downloads
15
Maintainers
Readme
cookier
Simple utility function to get, set and remove cookies
Install
npm install cookier
Import
import cookier from 'cookier';
Usage
Set cookies
cookier('cookieOne').set('true');
cookier('cookieTwo').set(JSON.stringify({
keyOne: 'valueOne',
keyTwo: 'valueTwo'
}));
Set cookies with expiry time
//sets a cookie with an expiry of 86400 seconds, or one day.
cookier('cookieOne').set('true', 1);
Get cookies
const cookieOne = cookier('cookieOne').get();
// this will equal 'true'
const cookieTwo = cookier('cookieTwo').get();
// this will equal '{"key":"value"}'
const cookieTwo = JSON.parse(cookier('cookieTwo').get());
/*
this will equal:
{
keyOne: 'valueOne',
keyTwo: 'valueTwo'
}
*/
Remove cookies
cookier('cookieOne').remove();