vue-web-storage
Advanced tools
Comparing version
# Changelog | ||
## [4.0.2](https://github.com/ankurk91/vue-web-storage/compare/4.0.1...4.0.2) | ||
* Fix issue [#13](https://github.com/ankurk91/vue-web-storage/issues/13) | ||
## [4.0.1](https://github.com/ankurk91/vue-web-storage/compare/4.0.0...4.0.1) | ||
@@ -4,0 +7,0 @@ * Add type definition |
@@ -165,9 +165,4 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
var storedValue = this.storage.getItem(this.prefixKey(key)); | ||
if (storedValue !== null) { | ||
return parseJSON(storedValue); | ||
} | ||
return defaultValue; | ||
var storedValue = parseJSON(this.storage.getItem(this.prefixKey(key))); | ||
return storedValue === null ? defaultValue : storedValue; | ||
} | ||
@@ -174,0 +169,0 @@ }, { |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("VueWebStorage",[],t):"object"==typeof exports?exports.VueWebStorage=t():e.VueWebStorage=t()}("undefined"!=typeof self?self:this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t);var r=function(e){try{return JSON.parse(e)}catch(t){return e}},o=function(e){return e instanceof Array?e:[e]};function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var a=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"app_",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"local";i(this,e),this.prefix=t,this.storage=window["".concat(String(n),"Storage")]}var t,n,o;return t=e,(n=[{key:"prefixKey",value:function(e){return this.prefix+String(e)}},{key:"set",value:function(e,t){try{return this.storage.setItem(this.prefixKey(e),JSON.stringify(t)),!0}catch(e){return!1}}},{key:"get",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=this.storage.getItem(this.prefixKey(e));return null!==n?r(n):t}},{key:"remove",value:function(e){return this.storage.removeItem(this.prefixKey(e))}},{key:"clear",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];t?this.storage.clear():this.keys(!0).map((function(t){e.storage.removeItem(t)}))}},{key:"keys",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],n=[];return Object.keys(this.storage).forEach((function(r,o){r.substr(0,e.prefix.length)===e.prefix&&n.push(t?r:r.substring(e.prefix.length))})),n}},{key:"hasKey",value:function(e){return-1!==this.keys().indexOf(e)}},{key:"length",value:function(){return this.keys().length}}])&&u(t.prototype,n),o&&u(t,o),e}();function f(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var c={},l=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),window.addEventListener("storage",this._onChange,!1)}var t,n,o;return t=e,(n=[{key:"_onChange",value:function(e){var t=this,n=c[e.key];if(n){var o=r(e.newValue),i=r(e.oldValue);n.map((function(n){n.call(t,o,i,e.url)}))}}},{key:"on",value:function(e,t){c[e]?c[e].push(t):c[e]=[t]}},{key:"off",value:function(e,t){var n=c[e];n&&n.length>1?n.splice(n.indexOf(t),1):delete c[e]}},{key:"clear",value:function(e){e?delete c[e]:c={}}},{key:"listeners",value:function(){return c}}])&&f(t.prototype,n),o&&f(t,o),e}();function s(e){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function p(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function y(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function v(e,t){return!t||"object"!==s(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function b(e,t){return(b=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var g=function(e){function t(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"app_",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"local";return p(this,t),(e=v(this,h(t).call(this,n,r))).events=new l,e}var n,r,o;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&b(e,t)}(t,e),n=t,(r=[{key:"on",value:function(e,t){return this.events.on(this.prefixKey(e),t),this}},{key:"off",value:function(e,t){return this.events.off(this.prefixKey(e),t),this}},{key:"clearEvents",value:function(e){var t=!!e&&this.prefixKey(e);return this.events.clear(t),this}}])&&y(n.prototype,r),o&&y(n,o),t}(a);function d(){return(d=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}n.d(t,"Plugin",(function(){return O})),n.d(t,"Storage",(function(){return a})),n.d(t,"StorageWithEvents",(function(){return g}));var m=function(e,t,n){var r=new g(n,t),o="$"+String(t)+"Storage";e[o]=r,e.prototype[o]=r},O=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=d({},{prefix:"app_",drivers:"local"},t);o(n.drivers).map((function(t){m(e,t,n.prefix)}))};t.default=O}])})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("VueWebStorage",[],t):"object"==typeof exports?exports.VueWebStorage=t():e.VueWebStorage=t()}("undefined"!=typeof self?self:this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t);var r=function(e){try{return JSON.parse(e)}catch(t){return e}},o=function(e){return e instanceof Array?e:[e]};function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var a=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"app_",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"local";i(this,e),this.prefix=t,this.storage=window["".concat(String(n),"Storage")]}var t,n,o;return t=e,(n=[{key:"prefixKey",value:function(e){return this.prefix+String(e)}},{key:"set",value:function(e,t){try{return this.storage.setItem(this.prefixKey(e),JSON.stringify(t)),!0}catch(e){return!1}}},{key:"get",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=r(this.storage.getItem(this.prefixKey(e)));return null===n?t:n}},{key:"remove",value:function(e){return this.storage.removeItem(this.prefixKey(e))}},{key:"clear",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];t?this.storage.clear():this.keys(!0).map((function(t){e.storage.removeItem(t)}))}},{key:"keys",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],n=[];return Object.keys(this.storage).forEach((function(r,o){r.substr(0,e.prefix.length)===e.prefix&&n.push(t?r:r.substring(e.prefix.length))})),n}},{key:"hasKey",value:function(e){return-1!==this.keys().indexOf(e)}},{key:"length",value:function(){return this.keys().length}}])&&u(t.prototype,n),o&&u(t,o),e}();function f(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var c={},l=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),window.addEventListener("storage",this._onChange,!1)}var t,n,o;return t=e,(n=[{key:"_onChange",value:function(e){var t=this,n=c[e.key];if(n){var o=r(e.newValue),i=r(e.oldValue);n.map((function(n){n.call(t,o,i,e.url)}))}}},{key:"on",value:function(e,t){c[e]?c[e].push(t):c[e]=[t]}},{key:"off",value:function(e,t){var n=c[e];n&&n.length>1?n.splice(n.indexOf(t),1):delete c[e]}},{key:"clear",value:function(e){e?delete c[e]:c={}}},{key:"listeners",value:function(){return c}}])&&f(t.prototype,n),o&&f(t,o),e}();function s(e){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function p(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function y(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function v(e,t){return!t||"object"!==s(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function b(e,t){return(b=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var g=function(e){function t(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"app_",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"local";return p(this,t),(e=v(this,h(t).call(this,n,r))).events=new l,e}var n,r,o;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&b(e,t)}(t,e),n=t,(r=[{key:"on",value:function(e,t){return this.events.on(this.prefixKey(e),t),this}},{key:"off",value:function(e,t){return this.events.off(this.prefixKey(e),t),this}},{key:"clearEvents",value:function(e){var t=!!e&&this.prefixKey(e);return this.events.clear(t),this}}])&&y(n.prototype,r),o&&y(n,o),t}(a);function d(){return(d=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}n.d(t,"Plugin",(function(){return O})),n.d(t,"Storage",(function(){return a})),n.d(t,"StorageWithEvents",(function(){return g}));var m=function(e,t,n){var r=new g(n,t),o="$"+String(t)+"Storage";e[o]=r,e.prototype[o]=r},O=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=d({},{prefix:"app_",drivers:"local"},t);o(n.drivers).map((function(t){m(e,t,n.prefix)}))};t.default=O}])})); |
{ | ||
"name": "vue-web-storage", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "Vue.js plugin for localStorage and sessionStorage", | ||
@@ -5,0 +5,0 @@ "main": "dist/vue-web-storage.js", |
@@ -94,3 +94,3 @@ # Vue Web Storage | ||
### Events | ||
* These are not regular Vue.js events, these [events](https://developer.mozilla.org/en-US/docs/Web/API/StorageEvent) to be used for cross tab communication. | ||
* :bulb: These are not regular Vue.js events, these [events](https://developer.mozilla.org/en-US/docs/Web/API/StorageEvent) to be used for cross tab communication. | ||
@@ -97,0 +97,0 @@ #### `on(key,fn)` |
@@ -25,7 +25,6 @@ import {parseJSON} from "./util"; | ||
get(key, defaultValue = null) { | ||
let storedValue = this.storage.getItem(this.prefixKey(key)); | ||
if (storedValue !== null) { | ||
return parseJSON(storedValue) | ||
} | ||
return defaultValue; | ||
const storedValue = parseJSON( | ||
this.storage.getItem(this.prefixKey(key)) | ||
); | ||
return storedValue === null ? defaultValue : storedValue; | ||
} | ||
@@ -32,0 +31,0 @@ |
35895
0.31%547
-0.73%