Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue2-storage

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue2-storage - npm Package Compare versions

Comparing version 5.0.0 to 5.1.0

36

dist/vue2-storage.common.js
/*!
* vue2-storage v5.0.0
* (c) 2019 Yarkov Aleksey
* vue2-storage v5.1.0
* (c) 2021 Yarkov Aleksey
* Released under the MIT License.

@@ -173,2 +173,3 @@ */

const availableDrivers = ['local', 'session', 'memory'];
class Vue2Storage {

@@ -188,3 +189,3 @@ constructor(config = {}) {

get version() {
return '5.0.0';
return '5.1.0';
}

@@ -208,2 +209,3 @@ get driver() {

};
this.checkConfig(config);
const options = objectAssign(defaultOptions, config);

@@ -298,2 +300,24 @@ this.options = Object.freeze(options);

}
checkConfig(config) {
if (config.prefix !== undefined) {
if (typeof config.prefix !== 'string') {
this.throwError(new TypeError('Option "prefix" must be a string'));
}
}
if (config.driver !== undefined) {
if (!availableDrivers.includes(config.driver)) {
this.throwError(new TypeError(`Option "driver" must be one of ${availableDrivers.join(', ')}`));
}
}
if (config.ttl !== undefined) {
if (typeof config.ttl !== 'number') {
this.throwError(new TypeError('Option "ttl" must be a number'));
}
}
if (config.replacer !== undefined) {
if (typeof config.replacer !== 'function') {
this.throwError(new TypeError('Option "replacer" must be a function'));
}
}
}
addPrefix(key) {

@@ -308,5 +332,11 @@ return `${this.options.prefix || ''}${key}`;

const ttl = ('ttl' in options) ? options.ttl : this.options.ttl;
const { replacer } = this.options;
return JSON.stringify({
value: data,
ttl: ttl > 0 ? ttl + Date.now() : 0,
}, (key, value) => {
if (!replacer || key !== 'value') {
return value;
}
return replacer(key, value);
});

@@ -313,0 +343,0 @@ }

@@ -7,2 +7,3 @@ import { PluginFunction } from 'vue';

ttl?: number
replacer?: <V extends any, R extends any>(key: string, value: V) => R
}

@@ -9,0 +10,0 @@

/*!
* vue2-storage v5.0.0
* (c) 2019 Yarkov Aleksey
* vue2-storage v5.1.0
* (c) 2021 Yarkov Aleksey
* Released under the MIT License.

@@ -169,2 +169,3 @@ */

const availableDrivers = ['local', 'session', 'memory'];
class Vue2Storage {

@@ -184,3 +185,3 @@ constructor(config = {}) {

get version() {
return '5.0.0';
return '5.1.0';
}

@@ -204,2 +205,3 @@ get driver() {

};
this.checkConfig(config);
const options = objectAssign(defaultOptions, config);

@@ -294,2 +296,24 @@ this.options = Object.freeze(options);

}
checkConfig(config) {
if (config.prefix !== undefined) {
if (typeof config.prefix !== 'string') {
this.throwError(new TypeError('Option "prefix" must be a string'));
}
}
if (config.driver !== undefined) {
if (!availableDrivers.includes(config.driver)) {
this.throwError(new TypeError(`Option "driver" must be one of ${availableDrivers.join(', ')}`));
}
}
if (config.ttl !== undefined) {
if (typeof config.ttl !== 'number') {
this.throwError(new TypeError('Option "ttl" must be a number'));
}
}
if (config.replacer !== undefined) {
if (typeof config.replacer !== 'function') {
this.throwError(new TypeError('Option "replacer" must be a function'));
}
}
}
addPrefix(key) {

@@ -304,5 +328,11 @@ return `${this.options.prefix || ''}${key}`;

const ttl = ('ttl' in options) ? options.ttl : this.options.ttl;
const { replacer } = this.options;
return JSON.stringify({
value: data,
ttl: ttl > 0 ? ttl + Date.now() : 0,
}, (key, value) => {
if (!replacer || key !== 'value') {
return value;
}
return replacer(key, value);
});

@@ -309,0 +339,0 @@ }

/*!
* vue2-storage v5.0.0
* (c) 2019 Yarkov Aleksey
* vue2-storage v5.1.0
* (c) 2021 Yarkov Aleksey
* Released under the MIT License.

@@ -175,2 +175,3 @@ */

const availableDrivers = ['local', 'session', 'memory'];
class Vue2Storage {

@@ -190,3 +191,3 @@ constructor(config = {}) {

get version() {
return '5.0.0';
return '5.1.0';
}

@@ -210,2 +211,3 @@ get driver() {

};
this.checkConfig(config);
const options = objectAssign(defaultOptions, config);

@@ -300,2 +302,24 @@ this.options = Object.freeze(options);

}
checkConfig(config) {
if (config.prefix !== undefined) {
if (typeof config.prefix !== 'string') {
this.throwError(new TypeError('Option "prefix" must be a string'));
}
}
if (config.driver !== undefined) {
if (!availableDrivers.includes(config.driver)) {
this.throwError(new TypeError(`Option "driver" must be one of ${availableDrivers.join(', ')}`));
}
}
if (config.ttl !== undefined) {
if (typeof config.ttl !== 'number') {
this.throwError(new TypeError('Option "ttl" must be a number'));
}
}
if (config.replacer !== undefined) {
if (typeof config.replacer !== 'function') {
this.throwError(new TypeError('Option "replacer" must be a function'));
}
}
}
addPrefix(key) {

@@ -310,5 +334,11 @@ return `${this.options.prefix || ''}${key}`;

const ttl = ('ttl' in options) ? options.ttl : this.options.ttl;
const { replacer } = this.options;
return JSON.stringify({
value: data,
ttl: ttl > 0 ? ttl + Date.now() : 0,
}, (key, value) => {
if (!replacer || key !== 'value') {
return value;
}
return replacer(key, value);
});

@@ -315,0 +345,0 @@ }

2

dist/vue2-storage.min.js

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):(t=t||self,e(t.Vue2Storage={}))}(this,function(t){"use strict";function e(t,e,r,n){return new(r||(r=Promise))(function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function c(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){t.done?i(t.value):new r(function(e){e(t.value)}).then(s,c)}u((n=n.apply(t,e||[])).next())})}function r(t){if(null===t||void 0===t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}var n=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable,s=function(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},r=0;r<10;r++)e["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(e).map(function(t){return e[t]}).join(""))return!1;var n={};return"abcdefghijklmnopqrst".split("").forEach(function(t){n[t]=t}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},n)).join("")}catch(t){return!1}}()?Object.assign:function(t,e){for(var s,c,u=r(t),f=1;f<arguments.length;f++){s=Object(arguments[f]);for(var h in s)i.call(s,h)&&(u[h]=s[h]);if(n){c=n(s);for(var a=0;a<c.length;a++)o.call(s,c[a])&&(u[c[a]]=s[c[a]])}}return u};const c={};class u{get length(){return Object.keys(this.storage).length}get storage(){return c}getItem(t){return t in this.storage?this.storage[t]:null}setItem(t,e){this.storage[t]=e}removeItem(t){t in this.storage&&delete this.storage[t]}clear(){const t=Object.keys(this.storage);for(let e=0;e<=t.length;e++)try{delete this.storage[t[e]]}catch(t){}}}var f,h=new u;!function(t){t.LOCAL="local",t.SESSION="session",t.MEMORY="memory"}(f||(f={}));class a extends Error{constructor(t,e){super(t),this.name="StorageError",e&&(this.stack=e)}}class l{constructor(t={}){this.setOptions(t)}get length(){return this.keys().length}get prefix(){return this.options.prefix}get name(){return"vue2-storage"}get version(){return"5.0.0"}get driver(){switch(this.options.driver){case f.LOCAL:default:return"undefined"!=typeof window?window.localStorage:h;case f.SESSION:return"undefined"!=typeof window?window.sessionStorage:h;case f.MEMORY:return h}}setOptions(t={}){const e={prefix:"app_",driver:f.LOCAL,ttl:0},r=s(e,t);this.options=Object.freeze(r)}get(t,e=null){try{const r=this.fromJSON(this.addPrefix(t));return null===r?e:r}catch(t){this.throwError(t)}}pull(t,e=null){const r=this.get(t,e);return r!==e&&this.remove(t),r}set(t,e,r={}){try{this.driver.setItem(this.addPrefix(t),this.toJSON(e,r))}catch(t){this.throwError(t)}}remember(t,r,n={}){return e(this,void 0,void 0,function*(){let e=this.get(t,null);if(null!==e)return e;try{return e=yield r(),this.set(t,e,n),e}catch(t){this.throwError(t)}})}remove(t){try{this.driver.removeItem(this.addPrefix(t))}catch(t){this.throwError(t)}}clear(t=!1){try{if(t)this.driver.clear();else{const t=this.keys().filter(t=>t.startsWith(this.options.prefix||""));t.forEach(t=>this.remove(this.removePrefix(t)))}}catch(t){this.throwError(t)}}has(t){return this.options.driver!==f.MEMORY?this.addPrefix(t)in this.driver:this.addPrefix(t)in this.driver.storage}key(t){try{const e=this.keys()[t];return this.get(this.removePrefix(e))}catch(t){this.throwError(t)}}keys(){return this.options.driver!==f.MEMORY?Object.keys(this.driver):Object.keys(this.driver.storage)}addPrefix(t){return`${this.options.prefix||""}${t}`}removePrefix(t){const e=new RegExp(`^${this.options.prefix||""}`);return t.replace(e,"")}toJSON(t,e={}){const r="ttl"in e?e.ttl:this.options.ttl;return JSON.stringify({value:t,ttl:r>0?r+Date.now():0})}fromJSON(t){try{const e=JSON.parse(this.driver.getItem(t));return null!==e?"ttl"in e&&Number(e.ttl)>0&&Number(e.ttl)<Date.now()?(this.remove(this.removePrefix(t)),null):"value"in e?e.value:e:null}catch(t){return null}}throwError(t){throw new a(`${this.name}[${this.version}]: ${t.message}`,t.stack)}}class d{static install(t,e){const r=new l(e);t.$storage=r,t.prototype.$storage=r}}"undefined"!=typeof window&&(window.Vue2Storage=d),t.Vue2Storage=d,t.default=d,Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):(t=t||self,e(t.Vue2Storage={}))}(this,function(t){"use strict";function e(t,e,r,n){return new(r||(r=Promise))(function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function c(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){t.done?i(t.value):new r(function(e){e(t.value)}).then(s,c)}u((n=n.apply(t,e||[])).next())})}function r(t){if(null===t||void 0===t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}var n=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable,s=function(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},r=0;r<10;r++)e["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(e).map(function(t){return e[t]}).join(""))return!1;var n={};return"abcdefghijklmnopqrst".split("").forEach(function(t){n[t]=t}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},n)).join("")}catch(t){return!1}}()?Object.assign:function(t,e){for(var s,c,u=r(t),f=1;f<arguments.length;f++){s=Object(arguments[f]);for(var h in s)i.call(s,h)&&(u[h]=s[h]);if(n){c=n(s);for(var a=0;a<c.length;a++)o.call(s,c[a])&&(u[c[a]]=s[c[a]])}}return u};const c={};class u{get length(){return Object.keys(this.storage).length}get storage(){return c}getItem(t){return t in this.storage?this.storage[t]:null}setItem(t,e){this.storage[t]=e}removeItem(t){t in this.storage&&delete this.storage[t]}clear(){const t=Object.keys(this.storage);for(let e=0;e<=t.length;e++)try{delete this.storage[t[e]]}catch(t){}}}var f,h=new u;!function(t){t.LOCAL="local",t.SESSION="session",t.MEMORY="memory"}(f||(f={}));class a extends Error{constructor(t,e){super(t),this.name="StorageError",e&&(this.stack=e)}}const l=["local","session","memory"];class p{constructor(t={}){this.setOptions(t)}get length(){return this.keys().length}get prefix(){return this.options.prefix}get name(){return"vue2-storage"}get version(){return"5.1.0"}get driver(){switch(this.options.driver){case f.LOCAL:default:return"undefined"!=typeof window?window.localStorage:h;case f.SESSION:return"undefined"!=typeof window?window.sessionStorage:h;case f.MEMORY:return h}}setOptions(t={}){const e={prefix:"app_",driver:f.LOCAL,ttl:0};this.checkConfig(t);const r=s(e,t);this.options=Object.freeze(r)}get(t,e=null){try{const r=this.fromJSON(this.addPrefix(t));return null===r?e:r}catch(t){this.throwError(t)}}pull(t,e=null){const r=this.get(t,e);return r!==e&&this.remove(t),r}set(t,e,r={}){try{this.driver.setItem(this.addPrefix(t),this.toJSON(e,r))}catch(t){this.throwError(t)}}remember(t,r,n={}){return e(this,void 0,void 0,function*(){let e=this.get(t,null);if(null!==e)return e;try{return e=yield r(),this.set(t,e,n),e}catch(t){this.throwError(t)}})}remove(t){try{this.driver.removeItem(this.addPrefix(t))}catch(t){this.throwError(t)}}clear(t=!1){try{if(t)this.driver.clear();else{const t=this.keys().filter(t=>t.startsWith(this.options.prefix||""));t.forEach(t=>this.remove(this.removePrefix(t)))}}catch(t){this.throwError(t)}}has(t){return this.options.driver!==f.MEMORY?this.addPrefix(t)in this.driver:this.addPrefix(t)in this.driver.storage}key(t){try{const e=this.keys()[t];return this.get(this.removePrefix(e))}catch(t){this.throwError(t)}}keys(){return this.options.driver!==f.MEMORY?Object.keys(this.driver):Object.keys(this.driver.storage)}checkConfig(t){void 0!==t.prefix&&"string"!=typeof t.prefix&&this.throwError(new TypeError('Option "prefix" must be a string')),void 0!==t.driver&&(l.includes(t.driver)||this.throwError(new TypeError(`Option "driver" must be one of ${l.join(", ")}`))),void 0!==t.ttl&&"number"!=typeof t.ttl&&this.throwError(new TypeError('Option "ttl" must be a number')),void 0!==t.replacer&&"function"!=typeof t.replacer&&this.throwError(new TypeError('Option "replacer" must be a function'))}addPrefix(t){return`${this.options.prefix||""}${t}`}removePrefix(t){const e=new RegExp(`^${this.options.prefix||""}`);return t.replace(e,"")}toJSON(t,e={}){const r="ttl"in e?e.ttl:this.options.ttl,{replacer:replacer}=this.options;return JSON.stringify({value:t,ttl:r>0?r+Date.now():0},(t,e)=>{if(!replacer||"value"!==t)return e;return replacer(t,e)})}fromJSON(t){try{const e=JSON.parse(this.driver.getItem(t));return null!==e?"ttl"in e&&Number(e.ttl)>0&&Number(e.ttl)<Date.now()?(this.remove(this.removePrefix(t)),null):"value"in e?e.value:e:null}catch(t){return null}}throwError(t){throw new a(`${this.name}[${this.version}]: ${t.message}`,t.stack)}}class d{static install(t,e){const r=new p(e);t.$storage=r,t.prototype.$storage=r}}"undefined"!=typeof window&&(window.Vue2Storage=d),t.Vue2Storage=d,t.default=d,Object.defineProperty(t,"__esModule",{value:!0})});
{
"name": "vue2-storage",
"description": "Browser storage for Vue.js app",
"version": "5.0.0",
"version": "5.1.0",
"author": {

@@ -6,0 +6,0 @@ "name": "Yarkov Aleksey",

@@ -5,19 +5,12 @@ # vue2-storage

[![Circle CI Status](https://circleci.com/gh/yarkovaleksei/vue2-storage.svg?style=shield)](https://circleci.com/gh/yarkovaleksei/vue2-storage)
[![npm](https://img.shields.io/npm/v/vue2-storage.svg)](https://www.npmjs.com/package/vue2-storage)
![GitHub release](https://img.shields.io/github/release/yarkovaleksei/vue2-storage.svg)
![GitHub release](https://img.shields.io/github/release/yarkovaleksei/vue2-storage.svg) ![node](https://img.shields.io/node/v/vue2-storage.svg) [![npm](https://img.shields.io/npm/v/vue2-storage.svg)](https://www.npmjs.com/package/vue2-storage) ![npm type definitions](https://img.shields.io/npm/types/vue2-storage.svg)
[![vue2](https://img.shields.io/badge/vue-2.x-brightgreen.svg)](https://vuejs.org/)
[![npm](https://img.shields.io/npm/dw/vue2-storage.svg)](https://www.npmjs.com/package/vue2-storage)
[![npm](https://img.shields.io/npm/dm/vue2-storage.svg)](https://www.npmjs.com/package/vue2-storage)
[![npm](https://img.shields.io/npm/dy/vue2-storage.svg)](https://www.npmjs.com/package/vue2-storage)
![node](https://img.shields.io/node/v/vue2-storage.svg)
![npm type definitions](https://img.shields.io/npm/types/vue2-storage.svg)
[![vue2](https://img.shields.io/badge/vue-2.x-brightgreen.svg)](https://vuejs.org/)
[![npm](https://img.shields.io/npm/dt/vue2-storage.svg)](https://www.npmjs.com/package/vue2-storage)
Browser storage for Vue.js app
## :book: Documentation
See [here](http://yarkovaleksei.github.io/vue2-storage/)
## :copyright: License
[MIT](http://opensource.org/licenses/MIT)
See [documentation](http://yarkovaleksei.github.io/vue2-storage/)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc