Comparing version 4.0.0 to 4.1.0
@@ -81,3 +81,5 @@ (function (global, factory) { | ||
var MemoryStorageInterface = /*#__PURE__*/function () { | ||
var MemoryStorageInterface = | ||
/*#__PURE__*/ | ||
function () { | ||
function MemoryStorageInterface() { | ||
@@ -134,3 +136,3 @@ _classCallCheck(this, MemoryStorageInterface); | ||
value: function removeItem(name) { | ||
var found = (name in ls); | ||
var found = name in ls; | ||
@@ -180,3 +182,5 @@ if (found) { | ||
var WebStorageEvent = /*#__PURE__*/function () { | ||
var WebStorageEvent = | ||
/*#__PURE__*/ | ||
function () { | ||
function WebStorageEvent() { | ||
@@ -262,3 +266,5 @@ _classCallCheck(this, WebStorageEvent); | ||
var WebStorage = /*#__PURE__*/function () { | ||
var WebStorage = | ||
/*#__PURE__*/ | ||
function () { | ||
/** | ||
@@ -452,11 +458,8 @@ * @param {Object} storage | ||
/** | ||
* Install plugin | ||
* use storage | ||
* | ||
* @param {Object} Vue | ||
* @param {Object} options | ||
* @returns {WebStorage} | ||
*/ | ||
install: function install(Vue) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
useStorage: function useStorage(options) { | ||
var _options = _objectSpread2(_objectSpread2({}, options), {}, { | ||
@@ -498,2 +501,22 @@ storage: options.storage || 'local', | ||
}, _options || {})); | ||
return { | ||
ls: ls, | ||
_options: _options | ||
}; | ||
}, | ||
/** | ||
* Install plugin | ||
* | ||
* @param {Object} Vue | ||
* @param {Object} options | ||
* @returns {WebStorage} | ||
*/ | ||
install: function install(Vue) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var _this$useStorage = this.useStorage(options), | ||
ls = _this$useStorage.ls, | ||
_options = _this$useStorage._options; | ||
Vue[_options.name] = ls; // eslint-disable-line | ||
@@ -500,0 +523,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).VueStorage=t()}(this,function(){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function t(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}function n(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function i(r){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?n(Object(i),!0).forEach(function(e){var t,n,o;t=r,o=i[n=e],n in t?Object.defineProperty(t,n,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[n]=o}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(i)):n(Object(i)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(i,e))})}return r}var a={},s=new(function(){function e(){o(this,e),Object.defineProperty(this,"length",{get:function(){return Object.keys(a).length}})}return t(e,[{key:"getItem",value:function(e){return e in a?a[e]:null}},{key:"setItem",value:function(e,t){return a[e]=t,!0}},{key:"removeItem",value:function(e){return!!(e in a)&&delete a[e]}},{key:"clear",value:function(){return a={},!0}},{key:"key",value:function(e){var t=Object.keys(a);return void 0!==t[e]?t[e]:null}}]),e}()),u={},c=function(){function e(){o(this,e)}return t(e,null,[{key:"on",value:function(e,t){void 0===u[e]&&(u[e]=[]),u[e].push(t)}},{key:"off",value:function(e,t){u[e].length?u[e].splice(u[e].indexOf(t),1):u[e]=[]}},{key:"emit",value:function(e){var t=e||window.event,n=function(t){try{return JSON.parse(t).value}catch(e){return t}};if(void 0!==t&&void 0!==t.key){var o=u[t.key];void 0!==o&&o.forEach(function(e){e(n(t.newValue),n(t.oldValue),t.url||t.uri)})}}}]),e}(),l=function(){function n(e){if(o(this,n),this.storage=e,this.options={namespace:"",events:["storage"]},Object.defineProperty(this,"length",{get:function(){return this.storage.length}}),"undefined"!=typeof window)for(var t in this.options.events)window.addEventListener?window.addEventListener(this.options.events[t],c.emit,!1):window.attachEvent?window.attachEvent("on".concat(this.options.events[t]),c.emit):window["on".concat(this.options.events[t])]=c.emit}return t(n,[{key:"setOptions",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};this.options=Object.assign(this.options,e)}},{key:"set",value:function(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null,o=JSON.stringify({value:t,expire:null!==n?(new Date).getTime()+n:null});this.storage.setItem(this.options.namespace+e,o)}},{key:"get",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,n=this.storage.getItem(this.options.namespace+e);if(null!==n)try{var o=JSON.parse(n);if(null===o.expire)return o.value;if(o.expire>=(new Date).getTime())return o.value;this.remove(e)}catch(e){return t}return t}},{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=[],t=0;t<this.length;t++){var n=this.storage.key(t);!1!==new RegExp("^".concat(this.options.namespace,".+"),"i").test(n)&&e.push(n)}for(var o in e)this.storage.removeItem(e[o])}}},{key:"on",value:function(e,t){c.on(this.options.namespace+e,t)}},{key:"off",value:function(e,t){c.off(this.options.namespace+e,t)}}]),n}(),f="undefined"!=typeof window?window:global||{},e={install:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=i(i({},t),{},{storage:t.storage||"local",name:t.name||"ls"});if(n.storage&&-1===["memory","local","session"].indexOf(n.storage))throw new Error('Vue-ls: Storage "'.concat(n.storage,'" is not supported'));var o=null;switch(n.storage){case"local":o="localStorage"in f?f.localStorage:null;break;case"session":o="sessionStorage"in f?f.sessionStorage:null;break;case"memory":o=s}o||(o=s,console.error('Vue-ls: Storage "'.concat(n.storage,'" is not supported your system, use memory storage')));var r=new l(o);r.setOptions(Object.assign(r.options,{namespace:""},n||{})),e[n.name]=r,Object.defineProperty(e.prototype||e.config.globalProperties,"$".concat(n.name),{get:function(){return r}})}};return f.VueStorage=e}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).VueStorage=t()}(this,function(){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function t(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}function n(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function i(r){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?n(Object(i),!0).forEach(function(e){var t,n,o;t=r,o=i[n=e],n in t?Object.defineProperty(t,n,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[n]=o}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(i)):n(Object(i)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(i,e))})}return r}var s={},a=new(function(){function e(){o(this,e),Object.defineProperty(this,"length",{get:function(){return Object.keys(s).length}})}return t(e,[{key:"getItem",value:function(e){return e in s?s[e]:null}},{key:"setItem",value:function(e,t){return s[e]=t,!0}},{key:"removeItem",value:function(e){return!!(e in s)&&delete s[e]}},{key:"clear",value:function(){return s={},!0}},{key:"key",value:function(e){var t=Object.keys(s);return void 0!==t[e]?t[e]:null}}]),e}()),u={},c=function(){function e(){o(this,e)}return t(e,null,[{key:"on",value:function(e,t){void 0===u[e]&&(u[e]=[]),u[e].push(t)}},{key:"off",value:function(e,t){u[e].length?u[e].splice(u[e].indexOf(t),1):u[e]=[]}},{key:"emit",value:function(e){var t=e||window.event,n=function(t){try{return JSON.parse(t).value}catch(e){return t}};if(void 0!==t&&void 0!==t.key){var o=u[t.key];void 0!==o&&o.forEach(function(e){e(n(t.newValue),n(t.oldValue),t.url||t.uri)})}}}]),e}(),l=function(){function n(e){if(o(this,n),this.storage=e,this.options={namespace:"",events:["storage"]},Object.defineProperty(this,"length",{get:function(){return this.storage.length}}),"undefined"!=typeof window)for(var t in this.options.events)window.addEventListener?window.addEventListener(this.options.events[t],c.emit,!1):window.attachEvent?window.attachEvent("on".concat(this.options.events[t]),c.emit):window["on".concat(this.options.events[t])]=c.emit}return t(n,[{key:"setOptions",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};this.options=Object.assign(this.options,e)}},{key:"set",value:function(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null,o=JSON.stringify({value:t,expire:null!==n?(new Date).getTime()+n:null});this.storage.setItem(this.options.namespace+e,o)}},{key:"get",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,n=this.storage.getItem(this.options.namespace+e);if(null!==n)try{var o=JSON.parse(n);if(null===o.expire)return o.value;if(o.expire>=(new Date).getTime())return o.value;this.remove(e)}catch(e){return t}return t}},{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=[],t=0;t<this.length;t++){var n=this.storage.key(t);!1!==new RegExp("^".concat(this.options.namespace,".+"),"i").test(n)&&e.push(n)}for(var o in e)this.storage.removeItem(e[o])}}},{key:"on",value:function(e,t){c.on(this.options.namespace+e,t)}},{key:"off",value:function(e,t){c.off(this.options.namespace+e,t)}}]),n}(),f="undefined"!=typeof window?window:global||{},e={useStorage:function(e){var t=i(i({},e),{},{storage:e.storage||"local",name:e.name||"ls"});if(t.storage&&-1===["memory","local","session"].indexOf(t.storage))throw new Error('Vue-ls: Storage "'.concat(t.storage,'" is not supported'));var n=null;switch(t.storage){case"local":n="localStorage"in f?f.localStorage:null;break;case"session":n="sessionStorage"in f?f.sessionStorage:null;break;case"memory":n=a}n||(n=a,console.error('Vue-ls: Storage "'.concat(t.storage,'" is not supported your system, use memory storage')));var o=new l(n);return o.setOptions(Object.assign(o.options,{namespace:""},t||{})),{ls:o,_options:t}},install:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=this.useStorage(t),o=n.ls,r=n._options;e[r.name]=o,Object.defineProperty(e.prototype||e.config.globalProperties,"$".concat(r.name),{get:function(){return o}})}};return f.VueStorage=e}); |
{ | ||
"name": "vue-ls", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "Vue plugin for work with LocalStorage from Vue context", | ||
@@ -5,0 +5,0 @@ "main": "dist/vue-ls.js", |
@@ -83,3 +83,3 @@ <p align="center"> | ||
options = { | ||
const options = { | ||
namespace: 'vuejs__', // key prefix | ||
@@ -115,3 +115,23 @@ name: 'ls', // name variable Vue.[ls] or this.[$ls], | ||
``` | ||
Use in js file | ||
``` js | ||
// localStore.js | ||
import Storage from 'vue-ls'; | ||
const options = { | ||
namespace: 'vuejs__', // key prefix | ||
name: 'ls', // name variable Vue.[ls] or this.[$ls], | ||
storage: 'local', // storage name session, local, memory | ||
}; | ||
const { ls } = Storage.useStorage(options) | ||
export default ls | ||
// somefile.js | ||
import ls from 'localStore.js'; | ||
ls.set('foo', 'boo'); | ||
ls.get('foo'); | ||
``` | ||
#### Global | ||
@@ -118,0 +138,0 @@ |
@@ -11,9 +11,8 @@ import { MemoryStorage, WebStorage } from './storage'; | ||
/** | ||
* Install plugin | ||
* use storage | ||
* | ||
* @param {Object} Vue | ||
* @param {Object} options | ||
* @returns {WebStorage} | ||
*/ | ||
install(Vue, options = {}) { | ||
useStorage(options) { | ||
const _options = { | ||
@@ -62,3 +61,15 @@ ...options, | ||
return { ls, _options }; | ||
}, | ||
/** | ||
* Install plugin | ||
* | ||
* @param {Object} Vue | ||
* @param {Object} options | ||
* @returns {WebStorage} | ||
*/ | ||
install(Vue, options = {}) { | ||
const { ls, _options } = this.useStorage(options); | ||
Vue[_options.name] = ls; // eslint-disable-line | ||
Object.defineProperty(Vue.prototype || Vue.config.globalProperties, `$${_options.name}`, { | ||
@@ -65,0 +76,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
40259
822
236