-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue-cookie.js
45 lines (39 loc) · 1.3 KB
/
vue-cookie.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(function () {
Number.isInteger = Number.isInteger || function (value) {
return typeof value === 'number' &&
isFinite(value) &&
Math.floor(value) === value;
};
var Cookie = require('tiny-cookie');
var VueCookie = {
install: function (Vue) {
Vue.prototype ? Vue.prototype.$cookies = this : Vue.config.globalProperties.$cookies = this;
Vue.cookie = this;
},
set: function (name, value, daysOrOptions) {
var opts = daysOrOptions;
if(Number.isInteger(daysOrOptions)) {
opts = {expires: daysOrOptions};
}
return Cookie.set(name, value, opts);
},
get: function (name) {
return Cookie.get(name);
},
delete: function (name, options) {
var opts = {expires: -1};
if(options !== undefined) {
opts = Object.assign(options, opts);
}
this.set(name, '', opts);
}
};
if (typeof exports == "object") {
module.exports = VueCookie;
} else if (typeof define == "function" && define.amd) {
define([], function(){ return VueCookie; })
} else if (window.Vue) {
window.VueCookie = VueCookie;
Vue.use(VueCookie);
}
})();