From 859e55f58db3bf0b3b3eb11d14b8b6f503ac21b0 Mon Sep 17 00:00:00 2001 From: Igor Ognichenko Date: Tue, 6 Mar 2018 07:15:44 +0200 Subject: [PATCH 1/8] refactoring --- CHANGELOG.md | 6 ++++++ build/rollup.config.js | 2 +- dist/vue-ls.js | 10 +++++----- dist/vue-ls.min.js | 2 +- examples/counter/index.html | 2 +- src/index.js | 6 +++--- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b13789..732bf85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,7 @@ +## 3.0.0 +- Rename class and global variable `VueLocalStorage` to `VueStorage` +## 2.4.0 + - Added session storage + - Added memory storage + - Added the ability to name a variable diff --git a/build/rollup.config.js b/build/rollup.config.js index 39bfdf0..08f6ad8 100644 --- a/build/rollup.config.js +++ b/build/rollup.config.js @@ -37,6 +37,6 @@ export default { output: { file: process.env.NODE_ENV === 'production' ? 'dist/vue-ls.min.js' : 'dist/vue-ls.js', format: 'umd', - name: 'VueLocalStorage', + name: 'VueStorage', } }; diff --git a/dist/vue-ls.js b/dist/vue-ls.js index 673e34c..5ee48c0 100644 --- a/dist/vue-ls.js +++ b/dist/vue-ls.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - (global.VueLocalStorage = factory()); + (global.VueStorage = factory()); }(this, (function () { 'use strict'; var ls = {}; @@ -384,7 +384,7 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument /** * @type {{install: (function(Object, Object): Storage)}} */ -var VueLocalStorage = { +var VueStorage = { /** * Install plugin * @@ -396,7 +396,7 @@ var VueLocalStorage = { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var _options = _extends({}, options, { - storage: !!options.storage ? options.storage : 'local', + storage: options.storage || 'local', name: options.name || 'ls' }); @@ -446,9 +446,9 @@ var VueLocalStorage = { }; if (typeof window !== 'undefined') { - window.VueLocalStorage = VueLocalStorage; + window.VueStorage = VueStorage; } -return VueLocalStorage; +return VueStorage; }))); diff --git a/dist/vue-ls.min.js b/dist/vue-ls.min.js index c2b2130..4f6ab38 100644 --- a/dist/vue-ls.min.js +++ b/dist/vue-ls.min.js @@ -1 +1 @@ -!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.VueLocalStorage=n()}(this,function(){"use strict";var e={},n={getItem:function(n){return n in e?e[n]:null},setItem:function(n,t){return e[n]=t,!0},removeItem:function(n){return!!(n in e)&&delete e[n]},clear:function(){return e={},!0},key:function(n){var t=Object.keys(e);return void 0!==t[n]?t[n]:null}};Object.defineProperty(n,"length",{get:function(){return Object.keys(e).length}});var t=function(){function e(e,n){for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:{};this.options=i(this.options,e)}},{key:"set",value:function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,o=JSON.stringify({value:n,expire:null!==t?(new Date).getTime()+t:null});this.storage.setItem(this.options.namespace+e,o)}},{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;n1&&void 0!==arguments[1]?arguments[1]:{},o=u({},t,{storage:t.storage?t.storage:"local",name:t.name||"ls"});if(o.storage&&-1===["memory","local","session"].indexOf(o.storage))throw new Error('Vue-ls: Storage "'+o.storage+'" is not supported');var r=null;switch(o.storage){case"local":r="undefined"!=typeof window&&"localStorage"in window?window.localStorage:null;break;case"session":r="undefined"!=typeof window&&"sessionStorage"in window?window.sessionStorage:null;break;case"memory":r=n}r||(r=n,console.error('Vue-ls: Storage "'+o.storage+'" is not supported your system, use memory storage'));var i=new s(r);i.setOptions(u(i.options,{namespace:""},o||{})),e[o.name]=i,Object.defineProperty(e.prototype,"$"+o.name,{get:function(){return i}})}};return"undefined"!=typeof window&&(window.VueLocalStorage=l),l}); +!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.VueStorage=n()}(this,function(){"use strict";var e={},n={getItem:function(n){return n in e?e[n]:null},setItem:function(n,t){return e[n]=t,!0},removeItem:function(n){return!!(n in e)&&delete e[n]},clear:function(){return e={},!0},key:function(n){var t=Object.keys(e);return void 0!==t[n]?t[n]:null}};Object.defineProperty(n,"length",{get:function(){return Object.keys(e).length}});var t=function(){function e(e,n){for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:{};this.options=i(this.options,e)}},{key:"set",value:function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,o=JSON.stringify({value:n,expire:null!==t?(new Date).getTime()+t:null});this.storage.setItem(this.options.namespace+e,o)}},{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;n1&&void 0!==arguments[1]?arguments[1]:{},o=u({},t,{storage:t.storage||"local",name:t.name||"ls"});if(o.storage&&-1===["memory","local","session"].indexOf(o.storage))throw new Error('Vue-ls: Storage "'+o.storage+'" is not supported');var r=null;switch(o.storage){case"local":r="undefined"!=typeof window&&"localStorage"in window?window.localStorage:null;break;case"session":r="undefined"!=typeof window&&"sessionStorage"in window?window.sessionStorage:null;break;case"memory":r=n}r||(r=n,console.error('Vue-ls: Storage "'+o.storage+'" is not supported your system, use memory storage'));var i=new s(r);i.setOptions(u(i.options,{namespace:""},o||{})),e[o.name]=i,Object.defineProperty(e.prototype,"$"+o.name,{get:function(){return i}})}};return"undefined"!=typeof window&&(window.VueStorage=l),l}); diff --git a/examples/counter/index.html b/examples/counter/index.html index bdec4a8..9e4bb6a 100644 --- a/examples/counter/index.html +++ b/examples/counter/index.html @@ -19,7 +19,7 @@

Synchronized tab counter