easier-cookie
v1.1.1
Published
A cookie library with a simple API provide
Downloads
9
Maintainers
Readme
easier-cookie
A cookie library with a simple API provide
Installation
npm install easier-cookie
cnpm install easier-cookie
Module Loaders
Now we support TypeScript.
JavaScript Cookie can also be loaded as an AMD or CommonJS module.
const Cookie = require('easier-cookie');
import Cookie from 'easier-cookie';
Basic Usage
- create cookie
Cookie.set accepts 3 arguments: key
, value
, options
options
is an Object which includes expires: day
, path
, domain
.
// Create a cookie, which value is Object
Cookie.set('name', {a:1}, {
expires: 7,
path: '/aaa',
domain: 'www.baidu.com'
});
// Create a cookie, which value is an Array
Cookie.set('array', ['1',2,3,4],
expires: 7,
});
// Create a cookie that expires 7 days from now
Cookie.set('name', 1, {expires: 7});
// Create an expiring cookie, valid to the path of the current page
Cookies.set('name', 'value', { expires: 7, path: '/' });
// Create an expiring cookie, which the domain is baidu
Cookie.set('to', 'baidu', {
expires: 7,
domain: 'www.baidu.com'
});
- get cookie
Cookies.get('name')
- remove cookie
Cookies.remove('name')