vue-localstorage
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "vue-localstorage", | ||
"version": "0.1.1", | ||
"description": "Vue.js localStorage plugin with types support", | ||
@@ -4,0 +5,0 @@ "main": "vue-localstorage.js", |
{ | ||
"name": "vue-localstorage", | ||
"version": "0.1.0", | ||
"description": "socket.io implemantation for vuejs", | ||
"main": "vue-localstorage.es2015.js", | ||
"version": "0.1.1", | ||
"description": "Vue.js localStorage plugin with types support", | ||
"main": "vue-localstorage.js", | ||
"repository": { | ||
@@ -7,0 +7,0 @@ "type": "git", |
@@ -44,3 +44,3 @@ # VueLocalStorage | ||
methods: { | ||
someMethod: { | ||
someMethod () { | ||
let lsValue = this.$localStorage.get('someObject') | ||
@@ -47,0 +47,0 @@ this.$localStorage.set('someBoolean', true) |
@@ -0,3 +1,8 @@ | ||
let ls = window.localStorage | ||
try { | ||
'localStorage' in window && window['localStorage'] !== null | ||
let test = '__vue-localstorage-test__' | ||
ls.setItem(test, test) | ||
ls.removeItem(test) | ||
} catch (e) { | ||
@@ -7,4 +12,2 @@ console.error('Local storage not supported by this browser') | ||
let ls = window.localStorage | ||
class VueLocalStorage { | ||
@@ -37,5 +40,7 @@ /** | ||
* | ||
* @param {String} lsKey | ||
* @param {*} value | ||
* @returns {*} | ||
*/ | ||
static set () { | ||
static set (lsKey, value) { | ||
for (let key in VueLocalStorage._properties) { | ||
@@ -42,0 +47,0 @@ let type = VueLocalStorage._properties[key].type |
;(function () { | ||
var ls = window.localStorage; | ||
try { | ||
'localStorage' in window && window['localStorage'] !== null; | ||
var test = '__vue-localstorage-test__'; | ||
ls.setItem(test, test); | ||
ls.removeItem(test); | ||
} catch (e) { | ||
@@ -13,3 +18,3 @@ console.error('Local storage not supported by this browser'); | ||
get: function (lsKey) { | ||
if (window.localStorage.hasOwnProperty(lsKey)) { | ||
if (ls.hasOwnProperty(lsKey)) { | ||
type = String; | ||
@@ -24,3 +29,3 @@ | ||
return VueLocalStorage._process(type, window.localStorage[lsKey]); | ||
return VueLocalStorage._process(type, ls[lsKey]); | ||
} | ||
@@ -36,3 +41,3 @@ | ||
if ((key === lsKey) && (type === Array || type === Object)) { | ||
window.localStorage[lsKey] = JSON.stringify(value); | ||
ls[lsKey] = JSON.stringify(value); | ||
return value; | ||
@@ -42,3 +47,3 @@ } | ||
window.localStorage[lsKey] = value; | ||
ls[lsKey] = value; | ||
@@ -49,3 +54,3 @@ return value; | ||
remove: function (lsKey) { | ||
return window.localStorage.removeItem(lsKey); | ||
return ls.removeItem(lsKey); | ||
}, | ||
@@ -61,3 +66,3 @@ // Private function that processes the value | ||
try { | ||
let array = JSON.parse(value); | ||
var array = JSON.parse(value); | ||
return Array.isArray(array) ? array : []; | ||
@@ -81,3 +86,3 @@ } catch (e) { | ||
var ls = { | ||
var localStoragePlugin = { | ||
install: function (Vue) { | ||
@@ -101,7 +106,7 @@ Vue.mixin({ | ||
if ( | ||
!window.localStorage.hasOwnProperty(key) && | ||
!ls.hasOwnProperty(key) && | ||
this.$options.localStorage[key].hasOwnProperty('default') | ||
) { | ||
value = this.$options.localStorage[key].default; | ||
window.localStorage[key] = (type === Array || type === Object) ? JSON.stringify(value) : value; | ||
ls[key] = (type === Array || type === Object) ? JSON.stringify(value) : value; | ||
} | ||
@@ -119,10 +124,10 @@ } | ||
if (typeof exports === 'object') { | ||
module.exports = ls; | ||
module.exports = localStoragePlugin; | ||
} else if (typeof define === 'function' && define.amd) { | ||
define([], function () { | ||
return ls; | ||
return localStoragePlugin; | ||
}) | ||
} else if (window.Vue) { | ||
window.VueLocalStorage = ls; | ||
window.VueLocalStorage = localStoragePlugin; | ||
} | ||
})(); |
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
11714
8
258