vue-localstorage
Advanced tools
Comparing version 0.4.1 to 0.4.2
/** | ||
* vue-local-storage v0.4.0 | ||
* vue-local-storage v0.4.2 | ||
* (c) 2017 Alexander Avakov | ||
* @license MIT | ||
*/ | ||
const ls = window.localStorage; | ||
class VueLocalStorage { | ||
@@ -24,3 +22,3 @@ /** | ||
get (lsKey, defaultValue = null) { | ||
if (ls[lsKey]) { | ||
if (window.localStorage[lsKey]) { | ||
let type = String; | ||
@@ -35,3 +33,3 @@ | ||
return this._process(type, ls[lsKey]) | ||
return this._process(type, window.localStorage[lsKey]) | ||
} | ||
@@ -54,3 +52,3 @@ | ||
if ((key === lsKey) && [Array, Object].includes(type)) { | ||
ls.setItem(lsKey, JSON.stringify(value)); | ||
window.localStorage.setItem(lsKey, JSON.stringify(value)); | ||
@@ -61,3 +59,3 @@ return value | ||
ls.setItem(lsKey, value); | ||
window.localStorage.setItem(lsKey, value); | ||
@@ -73,3 +71,3 @@ return value | ||
remove (lsKey) { | ||
return ls.removeItem(lsKey) | ||
return window.localStorage.removeItem(lsKey) | ||
} | ||
@@ -89,4 +87,4 @@ | ||
if (!ls[key] && defaultValue !== null) { | ||
ls.setItem(key, [Array, Object].includes(type) ? JSON.stringify(defaultValue) : defaultValue); | ||
if (!window.localStorage[key] && defaultValue !== null) { | ||
window.localStorage.setItem(key, [Array, Object].includes(type) ? JSON.stringify(defaultValue) : defaultValue); | ||
} | ||
@@ -139,3 +137,3 @@ } | ||
install: (Vue, options = {}) => { | ||
if (process && | ||
if (typeof process !== 'undefined' && | ||
( | ||
@@ -142,0 +140,0 @@ process.server || |
/** | ||
* vue-local-storage v0.4.0 | ||
* vue-local-storage v0.4.2 | ||
* (c) 2017 Alexander Avakov | ||
@@ -12,4 +12,2 @@ * @license MIT | ||
var ls = window.localStorage; | ||
var VueLocalStorage = function VueLocalStorage () { | ||
@@ -30,3 +28,3 @@ this._properties = {}; | ||
if (ls[lsKey]) { | ||
if (window.localStorage[lsKey]) { | ||
var type = String; | ||
@@ -41,3 +39,3 @@ | ||
return this._process(type, ls[lsKey]) | ||
return this._process(type, window.localStorage[lsKey]) | ||
} | ||
@@ -62,3 +60,3 @@ | ||
if ((key === lsKey) && [Array, Object].includes(type)) { | ||
ls.setItem(lsKey, JSON.stringify(value)); | ||
window.localStorage.setItem(lsKey, JSON.stringify(value)); | ||
@@ -69,3 +67,3 @@ return value | ||
ls.setItem(lsKey, value); | ||
window.localStorage.setItem(lsKey, value); | ||
@@ -81,3 +79,3 @@ return value | ||
VueLocalStorage.prototype.remove = function remove (lsKey) { | ||
return ls.removeItem(lsKey) | ||
return window.localStorage.removeItem(lsKey) | ||
}; | ||
@@ -97,4 +95,4 @@ | ||
if (!ls[key] && defaultValue !== null) { | ||
ls.setItem(key, [Array, Object].includes(type) ? JSON.stringify(defaultValue) : defaultValue); | ||
if (!window.localStorage[key] && defaultValue !== null) { | ||
window.localStorage.setItem(key, [Array, Object].includes(type) ? JSON.stringify(defaultValue) : defaultValue); | ||
} | ||
@@ -148,3 +146,3 @@ }; | ||
if (process && | ||
if (typeof process !== 'undefined' && | ||
( | ||
@@ -151,0 +149,0 @@ process.server || |
@@ -1,1 +0,1 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):e.VueLocalStorage=r()}(this,function(){"use strict";var e=window.localStorage,r=function(){this._properties={}};r.prototype.get=function(r,t){var o=this;if(void 0===t&&(t=null),e[r]){var n=String;for(var s in o._properties)if(s===r){n=o._properties[s].type;break}return this._process(n,e[r])}return null!==t?t:null},r.prototype.set=function(r,t){var o=this;for(var n in o._properties){var s=o._properties[n].type;if(n===r&&[Array,Object].includes(s))return e.setItem(r,JSON.stringify(t)),t}return e.setItem(r,t),t},r.prototype.remove=function(r){return e.removeItem(r)},r.prototype.addProperty=function(r,t,o){t=t||String,this._properties[r]={type:t},e[r]||null===o||e.setItem(r,[Array,Object].includes(t)?JSON.stringify(o):o)},r.prototype._process=function(e,r){switch(e){case Boolean:return"true"===r;case Number:return parseInt(r,10);case Array:try{var t=JSON.parse(r);return Array.isArray(t)?t:[]}catch(e){return[]}case Object:try{return JSON.parse(r)}catch(e){return{}}default:return r}};var t=new r;return{install:function(e,r){if(void 0===r&&(r={}),!process||!(process.server||process.SERVER_BUILD||process.env&&"server"===process.env.VUE_ENV)){try{var o="__vue-localstorage-test__";window.localStorage.setItem(o,o),window.localStorage.removeItem(o)}catch(e){console.error("Local storage is not supported")}var n=r.name||"localStorage";e.mixin({created:function(){var e=this;this.$options[n]&&Object.keys(this.$options[n]).forEach(function(r){var o=[e.$options[n][r].type,e.$options[n][r].default],s=o[0],i=o[1];t.addProperty(r,s,i)})}}),e[n]=t,e.prototype["$"+n]=t}}}}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):e.VueLocalStorage=r()}(this,function(){"use strict";var e=function(){this._properties={}};e.prototype.get=function(e,r){var t=this;if(void 0===r&&(r=null),window.localStorage[e]){var o=String;for(var n in t._properties)if(n===e){o=t._properties[n].type;break}return this._process(o,window.localStorage[e])}return null!==r?r:null},e.prototype.set=function(e,r){var t=this;for(var o in t._properties){var n=t._properties[o].type;if(o===e&&[Array,Object].includes(n))return window.localStorage.setItem(e,JSON.stringify(r)),r}return window.localStorage.setItem(e,r),r},e.prototype.remove=function(e){return window.localStorage.removeItem(e)},e.prototype.addProperty=function(e,r,t){r=r||String,this._properties[e]={type:r},window.localStorage[e]||null===t||window.localStorage.setItem(e,[Array,Object].includes(r)?JSON.stringify(t):t)},e.prototype._process=function(e,r){switch(e){case Boolean:return"true"===r;case Number:return parseInt(r,10);case Array:try{var t=JSON.parse(r);return Array.isArray(t)?t:[]}catch(e){return[]}case Object:try{return JSON.parse(r)}catch(e){return{}}default:return r}};var r=new e;return{install:function(e,t){if(void 0===t&&(t={}),"undefined"==typeof process||!(process.server||process.SERVER_BUILD||process.env&&"server"===process.env.VUE_ENV)){try{var o="__vue-localstorage-test__";window.localStorage.setItem(o,o),window.localStorage.removeItem(o)}catch(e){console.error("Local storage is not supported")}var n=t.name||"localStorage";e.mixin({created:function(){var e=this;this.$options[n]&&Object.keys(this.$options[n]).forEach(function(t){var o=[e.$options[n][t].type,e.$options[n][t].default],i=o[0],a=o[1];r.addProperty(t,i,a)})}}),e[n]=r,e.prototype["$"+n]=r}}}}); |
{ | ||
"name": "vue-localstorage", | ||
"description": "Vue.js localStorage plugin with types support", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Alexander Avakov", |
@@ -6,4 +6,3 @@ # VueLocalStorage | ||
LocalStorage plugin with types support for Vue.js and Vue.js 2. | ||
SSR supported! | ||
LocalStorage plugin inspired by Vue typed props which take a care of typecasting for Vue.js 1 and 2 with SSR support. | ||
@@ -10,0 +9,0 @@ ## Install |
@@ -11,3 +11,3 @@ import VueLocalStorage from './VueLocalStorage' | ||
install: (Vue, options = {}) => { | ||
if (process && | ||
if (typeof process !== 'undefined' && | ||
( | ||
@@ -14,0 +14,0 @@ process.server || |
@@ -1,3 +0,1 @@ | ||
const ls = window.localStorage | ||
class VueLocalStorage { | ||
@@ -19,3 +17,3 @@ /** | ||
get (lsKey, defaultValue = null) { | ||
if (ls[lsKey]) { | ||
if (window.localStorage[lsKey]) { | ||
let type = String | ||
@@ -30,3 +28,3 @@ | ||
return this._process(type, ls[lsKey]) | ||
return this._process(type, window.localStorage[lsKey]) | ||
} | ||
@@ -49,3 +47,3 @@ | ||
if ((key === lsKey) && [Array, Object].includes(type)) { | ||
ls.setItem(lsKey, JSON.stringify(value)) | ||
window.localStorage.setItem(lsKey, JSON.stringify(value)) | ||
@@ -56,3 +54,3 @@ return value | ||
ls.setItem(lsKey, value) | ||
window.localStorage.setItem(lsKey, value) | ||
@@ -68,3 +66,3 @@ return value | ||
remove (lsKey) { | ||
return ls.removeItem(lsKey) | ||
return window.localStorage.removeItem(lsKey) | ||
} | ||
@@ -84,4 +82,4 @@ | ||
if (!ls[key] && defaultValue !== null) { | ||
ls.setItem(key, [Array, Object].includes(type) ? JSON.stringify(defaultValue) : defaultValue) | ||
if (!window.localStorage[key] && defaultValue !== null) { | ||
window.localStorage.setItem(key, [Array, Object].includes(type) ? JSON.stringify(defaultValue) : defaultValue) | ||
} | ||
@@ -88,0 +86,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17393
446
69