@sycoraxya/iaspect_cookies
v1.1.9
Published
Getting, checking and setting cookies
Downloads
29
Readme
Cookies
Getting, checking and setting cookies
Installation:
npm install @sycoraxya/iaspect_cookies --save-dev
or
yarn add @sycoraxya/iaspect_cookies --dev
npm install @sycoraxya/[email protected] --save-dev
or
yarn add @sycoraxya/[email protected] --dev
See tags for version numbers
Usage:
Add the following line to your script
import Cookies from "@sycoraxya/iaspect_cookies";Or add the folder to your webpack.config:
resolve: {
modulesDirectories: [
'node_modules/@sycoraxya'
]
}
// And add the following line to your scripts
import Cookies from "iaspect_cookies";API:
Set Cookie
/**
* Sets a cookie with the provided name, value and days till expiration
* @param {Object} cookie
* @param {string} cookie.name - cookie name
* @param {string} [cookie.value] - cookie value. If not specified the cookie will be deleted.
* @param {number} [cookie.exDays = Session] - days till expiration
*/
Cookies.set({name: 'chocolateChip', value: 'Yum!', exDays: 42}); // Expires in 42 days
Cookies.set({name: 'chocolateChip', value: 'Yum!'}); // Expires at the end of the current session
Cookies.set({name: 'chocolateChip'}); // Deletes a cookieCheck Cookie
/**
* Returns true if the cookie with the provided name has the provided value
* @param {string} name
* @param {string} value
* @returns {boolean}
*/
Cookies.check('chocolateChip', 'Yum!'); // true
Cookies.check('chocolateChip', 'Yummy!'); // falseGet Cookie
/**
* Returns the cookie object of the provided name
* @param {string} name
* @returns {Object}
*/
Cookies.get('ChocolateChip'); // {name: 'chocolateChip', value: 'Yum!'}Delete Cookie
/**
* Deletes a cookie
* @param {String} name
*/
Cookies.delete('chocolateChip')