main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | import utils from './../utils.js';
|
---|
2 | import platform from '../platform/index.js';
|
---|
3 |
|
---|
4 | export default platform.hasStandardBrowserEnv ?
|
---|
5 |
|
---|
6 | // Standard browser envs support document.cookie
|
---|
7 | {
|
---|
8 | write(name, value, expires, path, domain, secure) {
|
---|
9 | const cookie = [name + '=' + encodeURIComponent(value)];
|
---|
10 |
|
---|
11 | utils.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
|
---|
12 |
|
---|
13 | utils.isString(path) && cookie.push('path=' + path);
|
---|
14 |
|
---|
15 | utils.isString(domain) && cookie.push('domain=' + domain);
|
---|
16 |
|
---|
17 | secure === true && cookie.push('secure');
|
---|
18 |
|
---|
19 | document.cookie = cookie.join('; ');
|
---|
20 | },
|
---|
21 |
|
---|
22 | read(name) {
|
---|
23 | const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
---|
24 | return (match ? decodeURIComponent(match[3]) : null);
|
---|
25 | },
|
---|
26 |
|
---|
27 | remove(name) {
|
---|
28 | this.write(name, '', Date.now() - 86400000);
|
---|
29 | }
|
---|
30 | }
|
---|
31 |
|
---|
32 | :
|
---|
33 |
|
---|
34 | // Non-standard browser env (web workers, react-native) lack needed support.
|
---|
35 | {
|
---|
36 | write() {},
|
---|
37 | read() {
|
---|
38 | return null;
|
---|
39 | },
|
---|
40 | remove() {}
|
---|
41 | };
|
---|
42 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.