Skip to content

Commit

Permalink
Upgrade to 6.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
yarkovaleksei committed Mar 20, 2021
1 parent 386ac86 commit f98895d
Show file tree
Hide file tree
Showing 23 changed files with 151 additions and 118 deletions.
46 changes: 34 additions & 12 deletions dist/vue2-storage.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* vue2-storage v6.0.0
* vue2-storage v6.0.3
* (c) 2021 Yarkov Aleksey
* Released under the MIT License.
*/
Expand Down Expand Up @@ -96,7 +96,7 @@ class Vue2Storage {
return 'vue2-storage';
}
get version() {
return '6.0.0';
return '6.0.3';
}
get driver() {
switch (this.options.driver) {
Expand Down Expand Up @@ -184,6 +184,7 @@ class Vue2Storage {
}
}
has(key) {
this.removeExpiredValuesByKeys([this.addPrefix(key)]);
if (this.options.driver !== StorageDriver.MEMORY) {
return (this.addPrefix(key) in this.driver);
}
Expand All @@ -199,10 +200,18 @@ class Vue2Storage {
}
}
keys() {
if (this.options.driver !== StorageDriver.MEMORY) {
return Object.keys(this.driver);
let keys = [];
switch (this.options.driver) {
case StorageDriver.MEMORY:
keys = Object.keys(this.driver.storage);
break;
default:
keys = Object.keys(this.driver);
break;
}
return Object.keys(this.driver.storage);
return keys.filter(key => {
return this.fromJSON(key) !== null;
});
}
checkConfig(config) {
if (config.prefix !== undefined) {
Expand All @@ -227,7 +236,7 @@ class Vue2Storage {
}
}
addPrefix(key) {
return `${this.options.prefix || ''}${key}`;
return `${this.options.prefix || ''}${this.removePrefix(key)}`;
}
removePrefix(key) {
const re = new RegExp(`^${this.options.prefix || ''}`);
Expand All @@ -248,14 +257,9 @@ class Vue2Storage {
}
fromJSON(key) {
try {
this.removeExpiredValuesByKeys([key]);
const data = JSON.parse(this.driver.getItem(key));
if (data !== null) {
if (('ttl' in data)
&& Number(data.ttl) > 0
&& Number(data.ttl) < Date.now()) {
this.remove(this.removePrefix(key));
return null;
}
if ('value' in data) {
return data.value;
}
Expand All @@ -267,6 +271,24 @@ class Vue2Storage {
return null;
}
}
removeExpiredValuesByKeys(keys) {
try {
keys.forEach(key => {
const data = JSON.parse(this.driver.getItem(key));
if (data === null) {
return;
}
if (('ttl' in data)
&& Number(data.ttl) > 0
&& Number(data.ttl) < Date.now()) {
this.remove(this.removePrefix(key));
}
});
}
catch (e) {
return null;
}
}
throwError(e) {
throw new StorageError(`${this.name}[${this.version}]: ${e.message}`, e.stack);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/vue2-storage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export declare class Vue2Storage {
get (key: string, fallback?: any): any;
pull (key: string, fallback?: any): any;
set (key: string, data: any, options?: SetterOptions): void;
remember (key: string, closure: () => Promise<any>, options?: SetterOptions): void;
remember <T = any>(key: string, closure: () => Promise<T>, options?: SetterOptions): Promise<T>;
remove (key: string): void;
clear (force?: boolean): void;
has (key: string): boolean;
Expand Down
46 changes: 34 additions & 12 deletions dist/vue2-storage.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* vue2-storage v6.0.0
* vue2-storage v6.0.3
* (c) 2021 Yarkov Aleksey
* Released under the MIT License.
*/
Expand Down Expand Up @@ -92,7 +92,7 @@ class Vue2Storage {
return 'vue2-storage';
}
get version() {
return '6.0.0';
return '6.0.3';
}
get driver() {
switch (this.options.driver) {
Expand Down Expand Up @@ -180,6 +180,7 @@ class Vue2Storage {
}
}
has(key) {
this.removeExpiredValuesByKeys([this.addPrefix(key)]);
if (this.options.driver !== StorageDriver.MEMORY) {
return (this.addPrefix(key) in this.driver);
}
Expand All @@ -195,10 +196,18 @@ class Vue2Storage {
}
}
keys() {
if (this.options.driver !== StorageDriver.MEMORY) {
return Object.keys(this.driver);
let keys = [];
switch (this.options.driver) {
case StorageDriver.MEMORY:
keys = Object.keys(this.driver.storage);
break;
default:
keys = Object.keys(this.driver);
break;
}
return Object.keys(this.driver.storage);
return keys.filter(key => {
return this.fromJSON(key) !== null;
});
}
checkConfig(config) {
if (config.prefix !== undefined) {
Expand All @@ -223,7 +232,7 @@ class Vue2Storage {
}
}
addPrefix(key) {
return `${this.options.prefix || ''}${key}`;
return `${this.options.prefix || ''}${this.removePrefix(key)}`;
}
removePrefix(key) {
const re = new RegExp(`^${this.options.prefix || ''}`);
Expand All @@ -244,14 +253,9 @@ class Vue2Storage {
}
fromJSON(key) {
try {
this.removeExpiredValuesByKeys([key]);
const data = JSON.parse(this.driver.getItem(key));
if (data !== null) {
if (('ttl' in data)
&& Number(data.ttl) > 0
&& Number(data.ttl) < Date.now()) {
this.remove(this.removePrefix(key));
return null;
}
if ('value' in data) {
return data.value;
}
Expand All @@ -263,6 +267,24 @@ class Vue2Storage {
return null;
}
}
removeExpiredValuesByKeys(keys) {
try {
keys.forEach(key => {
const data = JSON.parse(this.driver.getItem(key));
if (data === null) {
return;
}
if (('ttl' in data)
&& Number(data.ttl) > 0
&& Number(data.ttl) < Date.now()) {
this.remove(this.removePrefix(key));
}
});
}
catch (e) {
return null;
}
}
throwError(e) {
throw new StorageError(`${this.name}[${this.version}]: ${e.message}`, e.stack);
}
Expand Down
46 changes: 34 additions & 12 deletions dist/vue2-storage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* vue2-storage v6.0.0
* vue2-storage v6.0.3
* (c) 2021 Yarkov Aleksey
* Released under the MIT License.
*/
Expand Down Expand Up @@ -98,7 +98,7 @@
return 'vue2-storage';
}
get version() {
return '6.0.0';
return '6.0.3';
}
get driver() {
switch (this.options.driver) {
Expand Down Expand Up @@ -186,6 +186,7 @@
}
}
has(key) {
this.removeExpiredValuesByKeys([this.addPrefix(key)]);
if (this.options.driver !== StorageDriver.MEMORY) {
return (this.addPrefix(key) in this.driver);
}
Expand All @@ -201,10 +202,18 @@
}
}
keys() {
if (this.options.driver !== StorageDriver.MEMORY) {
return Object.keys(this.driver);
let keys = [];
switch (this.options.driver) {
case StorageDriver.MEMORY:
keys = Object.keys(this.driver.storage);
break;
default:
keys = Object.keys(this.driver);
break;
}
return Object.keys(this.driver.storage);
return keys.filter(key => {
return this.fromJSON(key) !== null;
});
}
checkConfig(config) {
if (config.prefix !== undefined) {
Expand All @@ -229,7 +238,7 @@
}
}
addPrefix(key) {
return `${this.options.prefix || ''}${key}`;
return `${this.options.prefix || ''}${this.removePrefix(key)}`;
}
removePrefix(key) {
const re = new RegExp(`^${this.options.prefix || ''}`);
Expand All @@ -250,14 +259,9 @@
}
fromJSON(key) {
try {
this.removeExpiredValuesByKeys([key]);
const data = JSON.parse(this.driver.getItem(key));
if (data !== null) {
if (('ttl' in data)
&& Number(data.ttl) > 0
&& Number(data.ttl) < Date.now()) {
this.remove(this.removePrefix(key));
return null;
}
if ('value' in data) {
return data.value;
}
Expand All @@ -269,6 +273,24 @@
return null;
}
}
removeExpiredValuesByKeys(keys) {
try {
keys.forEach(key => {
const data = JSON.parse(this.driver.getItem(key));
if (data === null) {
return;
}
if (('ttl' in data)
&& Number(data.ttl) > 0
&& Number(data.ttl) < Date.now()) {
this.remove(this.removePrefix(key));
}
});
}
catch (e) {
return null;
}
}
throwError(e) {
throw new StorageError(`${this.name}[${this.version}]: ${e.message}`, e.stack);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/vue2-storage.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f98895d

Please sign in to comment.