Comparing version 2.2.16 to 2.2.17
@@ -234,13 +234,17 @@ (function (global, factory) { | ||
if (item !== null) { | ||
var data = JSON.parse(item); | ||
try { | ||
var data = JSON.parse(item); | ||
if (data.expire === null) { | ||
return data.value; | ||
} | ||
if (data.expire === null) { | ||
return data.value; | ||
} | ||
if (data.expire >= new Date().getTime()) { | ||
return data.value; | ||
if (data.expire >= new Date().getTime()) { | ||
return data.value; | ||
} | ||
this.remove(name); | ||
} catch (err) { | ||
return def; | ||
} | ||
this.remove(name); | ||
} | ||
@@ -247,0 +251,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e["vue-ls"]=n()}(this,function(){"use strict";function e(e){function n(n){n(e.newValue?JSON.parse(e.newValue).value:e.newValue,e.oldValue?JSON.parse(e.oldValue).value:e.oldValue,e.url||e.uri)}if(e||(e=window.event),void 0!==e&&void 0!==e.key){var t=a[e.key];void 0!==t&&t.forEach(n)}}var n={},t={getItem:function(e){return e in n?n[e]:null},setItem:function(e,t){return n[e]=t,!0},removeItem:function(e){return!!(e in n)&&delete n[e]},clear:function(){return n={},!0},key:function(e){var t=Object.keys(n);return void 0!==t[e]?t[e]:null}};Object.defineProperty(t,"length",{get:function(){return Object.keys(n).length}});var o=function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")},i=function(){function e(e,n){for(var t=0;t<n.length;t++){var o=n[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(n,t,o){return t&&e(n.prototype,t),o&&e(n,o),n}}(),r=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},a={},s=new(function(){function n(t,i){if(o(this,n),this.storage=t,this.options=r({namespace:"",events:["storage"]},i||{}),Object.defineProperty(this,"length",{get:function(){return this.storage.length}}),"undefined"!=typeof window)for(var a in this.options.events)window.addEventListener?window.addEventListener(this.options.events[a],e,!1):window.attachEvent?window.attachEvent("on"+this.options.events[a],e):window["on"+this.options.events[a]]=e}return i(n,[{key:"set",value:function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.storage.setItem(this.options.namespace+e,JSON.stringify({value:n,expire:null!==t?(new Date).getTime()+t:null}))}},{key:"get",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,t=this.storage.getItem(this.options.namespace+e);if(null!==t){var o=JSON.parse(t);if(null===o.expire)return o.value;if(o.expire>=(new Date).getTime())return o.value;this.remove(e)}return n}},{key:"key",value:function(e){return this.storage.key(e)}},{key:"remove",value:function(e){return this.storage.removeItem(this.options.namespace+e)}},{key:"clear",value:function(){if(0!==this.length){for(var e=[],n=0;n<this.length;n++){var t=this.storage.key(n);!1!==new RegExp("^"+this.options.namespace+".+","i").test(t)&&e.push(t)}for(var o in e)this.storage.removeItem(e[o])}}},{key:"on",value:function(e,n){a[this.options.namespace+e]?a[this.options.namespace+e].push(n):a[this.options.namespace+e]=[n]}},{key:"off",value:function(e,n){var t=a[this.options.namespace+e];t.length>1?t.splice(t.indexOf(n),1):a[this.options.namespace+e]=[]}}]),n}())("undefined"!=typeof window&&"localStorage"in window?window.localStorage:t),u={install:function(e,n){s.options=r(s.options,{namespace:""},n||{}),e.ls=s,Object.defineProperty(e.prototype,"$ls",{get:function(){return s}})}};return"undefined"!=typeof window&&(window.VueLocalStorage=u),u}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e["vue-ls"]=n()}(this,function(){"use strict";function e(e){function n(n){n(e.newValue?JSON.parse(e.newValue).value:e.newValue,e.oldValue?JSON.parse(e.oldValue).value:e.oldValue,e.url||e.uri)}if(e||(e=window.event),void 0!==e&&void 0!==e.key){var t=a[e.key];void 0!==t&&t.forEach(n)}}var n={},t={getItem:function(e){return e in n?n[e]:null},setItem:function(e,t){return n[e]=t,!0},removeItem:function(e){return!!(e in n)&&delete n[e]},clear:function(){return n={},!0},key:function(e){var t=Object.keys(n);return void 0!==t[e]?t[e]:null}};Object.defineProperty(t,"length",{get:function(){return Object.keys(n).length}});var o=function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")},i=function(){function e(e,n){for(var t=0;t<n.length;t++){var o=n[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(n,t,o){return t&&e(n.prototype,t),o&&e(n,o),n}}(),r=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},a={},s=new(function(){function n(t,i){if(o(this,n),this.storage=t,this.options=r({namespace:"",events:["storage"]},i||{}),Object.defineProperty(this,"length",{get:function(){return this.storage.length}}),"undefined"!=typeof window)for(var a in this.options.events)window.addEventListener?window.addEventListener(this.options.events[a],e,!1):window.attachEvent?window.attachEvent("on"+this.options.events[a],e):window["on"+this.options.events[a]]=e}return i(n,[{key:"set",value:function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.storage.setItem(this.options.namespace+e,JSON.stringify({value:n,expire:null!==t?(new Date).getTime()+t:null}))}},{key:"get",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,t=this.storage.getItem(this.options.namespace+e);if(null!==t)try{var o=JSON.parse(t);if(null===o.expire)return o.value;if(o.expire>=(new Date).getTime())return o.value;this.remove(e)}catch(e){return n}return n}},{key:"key",value:function(e){return this.storage.key(e)}},{key:"remove",value:function(e){return this.storage.removeItem(this.options.namespace+e)}},{key:"clear",value:function(){if(0!==this.length){for(var e=[],n=0;n<this.length;n++){var t=this.storage.key(n);!1!==new RegExp("^"+this.options.namespace+".+","i").test(t)&&e.push(t)}for(var o in e)this.storage.removeItem(e[o])}}},{key:"on",value:function(e,n){a[this.options.namespace+e]?a[this.options.namespace+e].push(n):a[this.options.namespace+e]=[n]}},{key:"off",value:function(e,n){var t=a[this.options.namespace+e];t.length>1?t.splice(t.indexOf(n),1):a[this.options.namespace+e]=[]}}]),n}())("undefined"!=typeof window&&"localStorage"in window?window.localStorage:t),u={install:function(e,n){s.options=r(s.options,{namespace:""},n||{}),e.ls=s,Object.defineProperty(e.prototype,"$ls",{get:function(){return s}})}};return"undefined"!=typeof window&&(window.VueLocalStorage=u),u}); | ||
//# sourceMappingURL=vue-ls.min.js.map |
{ | ||
"name": "vue-ls", | ||
"version": "2.2.16", | ||
"version": "2.2.17", | ||
"description": "Vue plugin for work with LocalStorage from Vue context", | ||
@@ -74,3 +74,3 @@ "main": "dist/vue-ls.js", | ||
"coveralls": "^2.11.16", | ||
"eslint": "^3.16.1", | ||
"eslint": "^4.1.1", | ||
"get-gulp-args": "^0.0.1", | ||
@@ -94,6 +94,6 @@ "gulp": "github:gulpjs/gulp#4.0", | ||
"nightwatch": "^0.9.14", | ||
"nyc": "^10.1.2", | ||
"nyc": "^11.0.3", | ||
"phantomjs": "^2.1.7", | ||
"remove": "^0.1.5", | ||
"rollup": "^0.41.6", | ||
"rollup": "^0.43.0", | ||
"rollup-plugin-babel": "^2.7.1", | ||
@@ -103,3 +103,3 @@ "selenium-server": "^3.3.1", | ||
"vue": "^2.2.4", | ||
"webpack": "^2.3.1" | ||
"webpack": "^3.0.0" | ||
}, | ||
@@ -106,0 +106,0 @@ "semistandard": { |
@@ -92,13 +92,17 @@ const eventListeners = {}; | ||
if (item !== null) { | ||
let data = JSON.parse(item); | ||
try { | ||
let data = JSON.parse(item); | ||
if (data.expire === null) { | ||
return data.value; | ||
} | ||
if (data.expire === null) { | ||
return data.value; | ||
} | ||
if (data.expire >= new Date().getTime()) { | ||
return data.value; | ||
if (data.expire >= new Date().getTime()) { | ||
return data.value; | ||
} | ||
this.remove(name); | ||
} catch (err) { | ||
return def; | ||
} | ||
this.remove(name); | ||
} | ||
@@ -105,0 +109,0 @@ |
29348
595