function Cookie(key, value, opts) {
if (value === void 0) {
return Cookie.get(key);
} else if (value === null) {
Cookie.remove(key);
} else {
Cookie.set(key, value, opts);
}
}n/a
enabled = function () {
var key = '__test_key';
var enabled;
document.cookie = key + '=1';
enabled = !!document.cookie;
if (enabled) Cookie.remove(key);
return enabled;
}...
```bash
bower install tiny-cookie
```
## APIs
### Cookie.enabled()
Check if the cookie is enabled.
### Cookie.get(key)
**Alias: Cookie(key)**
...get = function (key, raw) {
if (typeof key !== 'string' || !key) return null;
key = '(?:^|; )' + escapeRe(key) + '(?:=([^;]*?))?(?:;|$)';
var reKey = new RegExp(key);
var res = reKey.exec(document.cookie);
return res !== null ? (raw ? res[1] : decodeURIComponent(res[1])) : null;
}...
## APIs
### Cookie.enabled()
Check if the cookie is enabled.
### Cookie.get(key)
**Alias: Cookie(key)**
Get the cookie value with decoding, using `decodeURIComponent`.
### Cookie.getRaw(key)
...getRaw = function (key) {
return Cookie.get(key, true);
}...
### Cookie.get(key)
**Alias: Cookie(key)**
Get the cookie value with decoding, using `decodeURIComponent`.
### Cookie.getRaw(key)
**Also: Cookie.get(key, true)**
Get the cookie value without decoding.
### Cookie.set(key, value, options)
...remove = function (key) {
Cookie.set(key, 'a', { expires: new Date() });
}...
### Cookie.setRaw(key, value, options)
**Also: Cookie.set(key, value, true, options)**
Set a cookie without encoding.
### Cookie.remove(key)
**Alias: Cookie(key, null)**
Remove a cookie.
## License
...set = function (key, value, raw, opts) {
if (raw !== true) {
opts = raw;
raw = false;
}
opts = opts ? convert(opts) : convert({});
var cookie = key + '=' + (raw ? value : encodeURIComponent(value)) + opts;
document.cookie = cookie;
}...
### Cookie.getRaw(key)
**Also: Cookie.get(key, true)**
Get the cookie value without decoding.
### Cookie.set(key, value, options)
**Alias: Cookie(key, value, options)**
Set a cookie with encoding the value, using `encodeURIComponent`. The `options` parameter is an object. And its property can be
a valid cookie option, such as `path`(default: root path `/`), `domain`, `expires`/`max-age` or `secure` (Note: the `secure` flag
will be set if it is an truthy value, such as `true`, or it will be not set). For example, you can set the expiration:
```js
var now = new Date;
...setRaw = function (key, value, opts) {
Cookie.set(key, value, true, opts);
}...
Cookie.set('stringSuffixM', 'One month later', { expires: '1M' });
Cookie.set('stringSuffixD', 'One day later', { expires: '1D' });
Cookie.set('stringSuffixh', 'One hour later', { expires: '1h' });
Cookie.set('stringSuffixm', 'Ten minutes later', { expires: '10m' });
Cookie.set('stringSuffixs', 'Thirty seconds later', { expires: '30s' });
```
### Cookie.setRaw(key, value, options)
**Also: Cookie.set(key, value, true, options)**
Set a cookie without encoding.
### Cookie.remove(key)
...