vue-web-storage
Advanced tools
Comparing version
@@ -9,2 +9,3 @@ import { parseJSON } from './util'; | ||
var _this = this; | ||
// According to specs the key can be `null` | ||
if (!event.key) | ||
@@ -11,0 +12,0 @@ return; |
@@ -65,3 +65,3 @@ import { parseJSON } from './util'; | ||
default: | ||
throw new Error('Unknown driver supplied'); | ||
throw new Error("Unknown driver supplied: " + driver); | ||
} | ||
@@ -68,0 +68,0 @@ }; |
@@ -187,3 +187,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
default: | ||
throw new Error('Unknown driver supplied'); | ||
throw new Error("Unknown driver supplied: " + driver); | ||
} | ||
@@ -204,2 +204,3 @@ }; | ||
var _this = this; | ||
// According to specs the key can be `null` | ||
if (!event.key) | ||
@@ -206,0 +207,0 @@ return; |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("VueWebStorage",[],e):"object"==typeof exports?exports.VueWebStorage=e():t.VueWebStorage=e()}("undefined"!=typeof self?self:this,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";r.r(e),r.d(e,"WebStorage",(function(){return i})),r.d(e,"StorageWithEvents",(function(){return p})),r.d(e,"Plugin",(function(){return c}));var n,o=function(t){return null===t?t:JSON.parse(t)},i=function(){function t(t,e){void 0===t&&(t="app_"),void 0===e&&(e="local"),this.prefix=t,this.storage=this.resolveDriver(e)}return t.prototype.prefixKey=function(t){return this.prefix+String(t)},t.prototype.set=function(t,e){return this.storage.setItem(this.prefixKey(t),JSON.stringify(e))},t.prototype.get=function(t,e){void 0===e&&(e=null);var r=null,n=this.storage.getItem(this.prefixKey(t));return n&&(r=o(n)),null===r?e:r},t.prototype.remove=function(t){return this.storage.removeItem(this.prefixKey(t))},t.prototype.clear=function(t){var e=this;void 0===t&&(t=!1),t?this.storage.clear():this.keys(!0).map((function(t){e.storage.removeItem(t)}))},t.prototype.keys=function(t){var e=this;void 0===t&&(t=!1);var r=[];return Object.keys(this.storage).forEach((function(n){n.substr(0,e.prefix.length)===e.prefix&&r.push(t?n:n.substring(e.prefix.length))})),r},t.prototype.hasKey=function(t){return-1!==this.keys().indexOf(t)},t.prototype.length=function(){return this.keys().length},t.prototype.resolveDriver=function(t){switch(t){case"local":return window.localStorage;case"session":return window.sessionStorage;default:throw new Error("Unknown driver supplied")}},t}(),u={},f=function(){function t(){window.addEventListener("storage",this.onChange,!1)}return t.prototype.onChange=function(t){var e=this;if(t.key){var r=u[t.key];if(r){var n=o(t.newValue),i=o(t.oldValue);r.map((function(r){r.call(e,n,i,t.url)}))}}},t.prototype.on=function(t,e){u[t]?u[t].push(e):u[t]=[e]},t.prototype.off=function(t,e){var r=u[t];r&&r.length>1?r.splice(r.indexOf(e),1):delete u[t]},t.prototype.clear=function(t){t?delete u[t]:u={}},t.prototype.listeners=function(){return u},t}(),s=(n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,e)},function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),p=function(t){function e(e,r){void 0===e&&(e="app_"),void 0===r&&(r="local");var n=t.call(this,e,r)||this;return n.events=new f,n}return s(e,t),e.prototype.on=function(t,e){return this.events.on(this.prefixKey(t),e),this},e.prototype.off=function(t,e){return this.events.off(this.prefixKey(t),e),this},e.prototype.clearEvents=function(t){var e=!!t&&this.prefixKey(t);return this.events.clear(e),this},e}(i),c=function(t,e){void 0===e&&(e={});var r,n=Object.assign({},{prefix:"app_",drivers:"local"},e);(r=n.drivers,r instanceof Array?r:[r]).map((function(e){!function(t,e,r){var n=new p(r,e),o="$"+String(e)+"Storage";t[o]=n,t.prototype[o]=n}(t,e,n.prefix)}))};e.default=c}])})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("VueWebStorage",[],e):"object"==typeof exports?exports.VueWebStorage=e():t.VueWebStorage=e()}("undefined"!=typeof self?self:this,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";r.r(e),r.d(e,"WebStorage",(function(){return i})),r.d(e,"StorageWithEvents",(function(){return p})),r.d(e,"Plugin",(function(){return c}));var n,o=function(t){return null===t?t:JSON.parse(t)},i=function(){function t(t,e){void 0===t&&(t="app_"),void 0===e&&(e="local"),this.prefix=t,this.storage=this.resolveDriver(e)}return t.prototype.prefixKey=function(t){return this.prefix+String(t)},t.prototype.set=function(t,e){return this.storage.setItem(this.prefixKey(t),JSON.stringify(e))},t.prototype.get=function(t,e){void 0===e&&(e=null);var r=null,n=this.storage.getItem(this.prefixKey(t));return n&&(r=o(n)),null===r?e:r},t.prototype.remove=function(t){return this.storage.removeItem(this.prefixKey(t))},t.prototype.clear=function(t){var e=this;void 0===t&&(t=!1),t?this.storage.clear():this.keys(!0).map((function(t){e.storage.removeItem(t)}))},t.prototype.keys=function(t){var e=this;void 0===t&&(t=!1);var r=[];return Object.keys(this.storage).forEach((function(n){n.substr(0,e.prefix.length)===e.prefix&&r.push(t?n:n.substring(e.prefix.length))})),r},t.prototype.hasKey=function(t){return-1!==this.keys().indexOf(t)},t.prototype.length=function(){return this.keys().length},t.prototype.resolveDriver=function(t){switch(t){case"local":return window.localStorage;case"session":return window.sessionStorage;default:throw new Error("Unknown driver supplied: "+t)}},t}(),u={},f=function(){function t(){window.addEventListener("storage",this.onChange,!1)}return t.prototype.onChange=function(t){var e=this;if(t.key){var r=u[t.key];if(r){var n=o(t.newValue),i=o(t.oldValue);r.map((function(r){r.call(e,n,i,t.url)}))}}},t.prototype.on=function(t,e){u[t]?u[t].push(e):u[t]=[e]},t.prototype.off=function(t,e){var r=u[t];r&&r.length>1?r.splice(r.indexOf(e),1):delete u[t]},t.prototype.clear=function(t){t?delete u[t]:u={}},t.prototype.listeners=function(){return u},t}(),s=(n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,e)},function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),p=function(t){function e(e,r){void 0===e&&(e="app_"),void 0===r&&(r="local");var n=t.call(this,e,r)||this;return n.events=new f,n}return s(e,t),e.prototype.on=function(t,e){return this.events.on(this.prefixKey(t),e),this},e.prototype.off=function(t,e){return this.events.off(this.prefixKey(t),e),this},e.prototype.clearEvents=function(t){var e=!!t&&this.prefixKey(t);return this.events.clear(e),this},e}(i),c=function(t,e){void 0===e&&(e={});var r,n=Object.assign({},{prefix:"app_",drivers:"local"},e);(r=n.drivers,r instanceof Array?r:[r]).map((function(e){!function(t,e,r){var n=new p(r,e),o="$"+String(e)+"Storage";t[o]=n,t.prototype[o]=n}(t,e,n.prefix)}))};e.default=c}])})); |
@@ -9,3 +9,3 @@ import WebStorage from './webStorage'; | ||
} | ||
declare const Plugin: (Vue: any, options?: PluginOptions) => void; | ||
declare const Plugin: PluginFunction<PluginOptions>; | ||
export interface VueWebStoragePlugin extends PluginObject<PluginOptions> { | ||
@@ -12,0 +12,0 @@ install: PluginFunction<PluginOptions>; |
@@ -5,3 +5,3 @@ import WebStorage from './webStorage'; | ||
export default class StorageWithEvents extends WebStorage { | ||
events: Events; | ||
readonly events: Events; | ||
constructor(prefix?: string, driver?: driverType); | ||
@@ -8,0 +8,0 @@ on(key: string, fn: listenerCallback): this; |
import { driverType } from "./interfaces"; | ||
export default class WebStorage { | ||
prefix: string; | ||
storage: Storage; | ||
readonly prefix: string; | ||
readonly storage: Storage; | ||
constructor(prefix?: string, driver?: driverType); | ||
@@ -6,0 +6,0 @@ prefixKey(key: string): string; |
{ | ||
"name": "vue-web-storage", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "Vue.js plugin for localStorage and sessionStorage", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.umd.js", |
@@ -31,4 +31,4 @@ # Vue Web Storage | ||
import Vue from 'vue'; | ||
import Storage from 'vue-web-storage'; | ||
Vue.use(Storage); | ||
import StoragePlugin from 'vue-web-storage'; | ||
Vue.use(StoragePlugin); | ||
// Use as | ||
@@ -40,5 +40,5 @@ // Vue.$localStorage | ||
```js | ||
Vue.use(Storage, { | ||
Vue.use(StoragePlugin, { | ||
prefix: 'your_app_slug_',// default `app_` | ||
drivers: ['session','local'], // default 'local' | ||
drivers: ['session', 'local'], // default 'local' | ||
}); | ||
@@ -52,7 +52,7 @@ | ||
### Methods | ||
All methods take care of `prefix` in key name, so you no need to specify key prefix when using them. | ||
All methods take care of `prefix` in key name, so you no need to specify the prefix when using them. | ||
#### `set(key,value)` | ||
Stores the `value` under specified `key` in storage. Convert value to JSON before saving. | ||
Returns `true` on success and `false` on errors. | ||
This method throws error on failure. | ||
```js | ||
@@ -66,3 +66,3 @@ Vue.$localStorage.set('name', 'john') | ||
Retrieves given `key` value from storage, parse the value from JSON before returning. | ||
If parsing failed then returns the actual value get from storage. | ||
If parsing failed then throws error. | ||
```js | ||
@@ -104,3 +104,3 @@ Vue.$localStorage.get('name') | ||
```js | ||
const onChangeName = (newValue, OldValue, url) => { | ||
const onChangeName = (newValue, OldValue, originUrl) => { | ||
// do something when `name` value gets changed | ||
@@ -107,0 +107,0 @@ }; |
@@ -13,2 +13,3 @@ import {parseJSON} from './util'; | ||
private onChange(event: StorageEvent): void { | ||
// According to specs the key can be `null` | ||
if (!event.key) return; | ||
@@ -15,0 +16,0 @@ |
@@ -21,3 +21,3 @@ import WebStorage from './webStorage'; | ||
const Plugin = (Vue: any, options: PluginOptions = {}) => { | ||
const Plugin: PluginFunction<PluginOptions> = (Vue: any, options: PluginOptions = {}) => { | ||
@@ -24,0 +24,0 @@ let safeOptions = Object.assign({}, { |
@@ -7,3 +7,3 @@ import WebStorage from './webStorage'; | ||
public events: Events; | ||
public readonly events: Events; | ||
@@ -10,0 +10,0 @@ constructor(prefix = 'app_', driver: driverType = 'local') { |
@@ -6,5 +6,5 @@ import {parseJSON} from './util'; | ||
public storage: Storage; | ||
public readonly storage: Storage; | ||
constructor(public prefix = 'app_', driver: driverType = 'local') { | ||
constructor(public readonly prefix = 'app_', driver: driverType = 'local') { | ||
this.storage = this.resolveDriver(driver); | ||
@@ -73,5 +73,5 @@ } | ||
default: | ||
throw new Error('Unknown driver supplied') | ||
throw new Error(`Unknown driver supplied: ${driver}`) | ||
} | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
38994
0.63%743
0.41%0
-100%