@esportsplus/web-storage 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.d.ts +25 -23
- package/build/local/index.d.ts +3 -1
- package/build/local/index.js +4 -2
- package/package.json +1 -2
- package/src/local/index.ts +4 -2
- package/build/local/instance.d.ts +0 -5
- package/build/local/instance.js +0 -20
- package/build/local/object.d.ts +0 -3
- package/build/local/object.js +0 -123
package/build/index.d.ts
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
import local from './local';
|
|
2
2
|
declare const _default: {
|
|
3
|
-
local:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
3
|
+
local: {
|
|
4
|
+
store: (options?: LocalForageOptions) => {
|
|
5
|
+
instance: LocalForage;
|
|
6
|
+
iterate: <T, U>(iteratee: (value: T, key: string, iterationNumber: number) => U, callback?: ((err: any, result: U) => void) | undefined) => Promise<U>;
|
|
7
|
+
keys: (callback?: ((err: any, keys: string[]) => void) | undefined) => Promise<string[]>;
|
|
8
|
+
length: (callback?: ((err: any, numberOfKeys: number) => void) | undefined) => Promise<number>;
|
|
9
|
+
promises: (Promise<any> | (() => void))[];
|
|
10
|
+
assign(key: string, value: import("./local/types").Object): void;
|
|
11
|
+
clear(): Promise<void>;
|
|
12
|
+
delete(...keys: string[]): void;
|
|
13
|
+
entries(): Promise<import("./local/types").Object>;
|
|
14
|
+
filter(fn: Function): Promise<import("./local/types").Object>;
|
|
15
|
+
get(key: string, value?: any): Promise<any>;
|
|
16
|
+
has(...keys: string[]): Promise<boolean>;
|
|
17
|
+
only(...keys: string[]): Promise<import("./local/types").Object>;
|
|
18
|
+
pop(key: string): Promise<any>;
|
|
19
|
+
push(key: string, ...values: any[]): void;
|
|
20
|
+
replace(values: {
|
|
21
|
+
[key: string]: any;
|
|
22
|
+
}): void;
|
|
23
|
+
shift(key: string): Promise<any>;
|
|
24
|
+
set(key: string, value: any): void;
|
|
25
|
+
sync(): Promise<void>;
|
|
26
|
+
unshift(key: string, ...values: any[]): void;
|
|
27
|
+
};
|
|
26
28
|
};
|
|
27
29
|
};
|
|
28
30
|
export default _default;
|
package/build/local/index.d.ts
CHANGED
|
@@ -24,5 +24,7 @@ declare class Store {
|
|
|
24
24
|
sync(): Promise<void>;
|
|
25
25
|
unshift(key: string, ...values: any[]): void;
|
|
26
26
|
}
|
|
27
|
-
declare const _default:
|
|
27
|
+
declare const _default: {
|
|
28
|
+
store: (options?: LocalForageOptions) => Store;
|
|
29
|
+
};
|
|
28
30
|
export default _default;
|
package/build/local/index.js
CHANGED
|
@@ -21,7 +21,7 @@ class Store {
|
|
|
21
21
|
driver = localforage_1.default.INDEXEDDB;
|
|
22
22
|
break;
|
|
23
23
|
}
|
|
24
|
-
this.instance = localforage_1.default.createInstance(Object.assign(options, { driver, name }));
|
|
24
|
+
this.instance = localforage_1.default.createInstance(Object.assign(options, { driver, name, storeName: name }));
|
|
25
25
|
this.iterate = this.instance.iterate;
|
|
26
26
|
this.keys = this.instance.keys;
|
|
27
27
|
this.length = this.instance.length;
|
|
@@ -135,4 +135,6 @@ class Store {
|
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
exports.default =
|
|
138
|
+
exports.default = {
|
|
139
|
+
store: (options = {}) => new Store(options)
|
|
140
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "ICJR",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@esportsplus/dot": "^0.0.3",
|
|
5
4
|
"localforage": "^1.10.0"
|
|
6
5
|
},
|
|
7
6
|
"description": "Web storage utility",
|
|
@@ -24,5 +23,5 @@
|
|
|
24
23
|
"prepublishOnly": "npm run build"
|
|
25
24
|
},
|
|
26
25
|
"types": "./build/index.d.ts",
|
|
27
|
-
"version": "0.1.
|
|
26
|
+
"version": "0.1.2"
|
|
28
27
|
}
|
package/src/local/index.ts
CHANGED
|
@@ -23,7 +23,7 @@ class Store {
|
|
|
23
23
|
break;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
this.instance = localforage.createInstance( Object.assign(options, { driver, name }) );
|
|
26
|
+
this.instance = localforage.createInstance( Object.assign(options, { driver, name, storeName: name }) );
|
|
27
27
|
this.iterate = this.instance.iterate;
|
|
28
28
|
this.keys = this.instance.keys;
|
|
29
29
|
this.length = this.instance.length;
|
|
@@ -186,4 +186,6 @@ class Store {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
|
|
189
|
-
export default
|
|
189
|
+
export default {
|
|
190
|
+
store: (options: LocalForageOptions = {}): Store => new Store(options)
|
|
191
|
+
};
|
package/build/local/instance.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const types_1 = require("./types");
|
|
7
|
-
const localforage_1 = __importDefault(require("localforage"));
|
|
8
|
-
const create = (options = {}) => {
|
|
9
|
-
let driver, name = options.name || 'store';
|
|
10
|
-
switch ((options.driver || types_1.Driver.IndexedDB)) {
|
|
11
|
-
case types_1.Driver.LocalStorage:
|
|
12
|
-
driver = localforage_1.default.LOCALSTORAGE;
|
|
13
|
-
break;
|
|
14
|
-
default:
|
|
15
|
-
driver = localforage_1.default.INDEXEDDB;
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
return localforage_1.default.createInstance(Object.assign(options, { driver, name }));
|
|
19
|
-
};
|
|
20
|
-
exports.default = { create };
|
package/build/local/object.d.ts
DELETED
package/build/local/object.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const instance_1 = __importDefault(require("./instance"));
|
|
7
|
-
function Store(options = {}) {
|
|
8
|
-
this.instance = instance_1.default.create(options);
|
|
9
|
-
this.iterate = this.instance.iterate;
|
|
10
|
-
this.keys = this.instance.keys;
|
|
11
|
-
this.length = this.instance.length;
|
|
12
|
-
this.promises = [];
|
|
13
|
-
}
|
|
14
|
-
Store.prototype = {
|
|
15
|
-
assign: function (key, value) {
|
|
16
|
-
this.promises.push(async () => {
|
|
17
|
-
let data = (await this.get(key)) || {};
|
|
18
|
-
await this.instance.setItem(key, Object.assign(data, value));
|
|
19
|
-
});
|
|
20
|
-
},
|
|
21
|
-
clear: function () {
|
|
22
|
-
this.promises = [];
|
|
23
|
-
return this.instance.clear();
|
|
24
|
-
},
|
|
25
|
-
delete: function (...keys) {
|
|
26
|
-
this.promises.push(async () => {
|
|
27
|
-
for (let i = 0, n = keys.length; i < n; i++) {
|
|
28
|
-
await this.instance.removeItem(keys[i]);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
},
|
|
32
|
-
entries: async function () {
|
|
33
|
-
let values = {};
|
|
34
|
-
await this.instance.iterate((value, key) => {
|
|
35
|
-
values[key] = value;
|
|
36
|
-
});
|
|
37
|
-
return values;
|
|
38
|
-
},
|
|
39
|
-
filter: async function (fn) {
|
|
40
|
-
let values = {};
|
|
41
|
-
await this.instance.iterate((value, key) => {
|
|
42
|
-
let result = fn(value, key), stop = typeof result !== 'boolean';
|
|
43
|
-
if (stop || (!stop && result)) {
|
|
44
|
-
values[key] = value;
|
|
45
|
-
}
|
|
46
|
-
if (stop) {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
return values;
|
|
51
|
-
},
|
|
52
|
-
get: async function (key, value = null) {
|
|
53
|
-
let data = await this.instance.getItem(key);
|
|
54
|
-
if (data === null) {
|
|
55
|
-
if (typeof value === 'function') {
|
|
56
|
-
data = await value();
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
data = value;
|
|
60
|
-
}
|
|
61
|
-
if (data !== null) {
|
|
62
|
-
this.set(key, data);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (data === null) {
|
|
66
|
-
throw new Error(`'${key}' has not been set in Storage`);
|
|
67
|
-
}
|
|
68
|
-
return data;
|
|
69
|
-
},
|
|
70
|
-
has: async function (...keys) {
|
|
71
|
-
let haystack = await this.instance.keys();
|
|
72
|
-
for (let i = 0, n = keys.length; i < n; i++) {
|
|
73
|
-
if (haystack.includes(keys[i])) {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
return true;
|
|
79
|
-
},
|
|
80
|
-
only: async function (...keys) {
|
|
81
|
-
return await this.filter((key) => keys.includes(key));
|
|
82
|
-
},
|
|
83
|
-
pop: async function (key) {
|
|
84
|
-
let value, values = (await this.get(key)) || [];
|
|
85
|
-
value = values.pop();
|
|
86
|
-
this.promises.push(this.instance.setItem(key, values));
|
|
87
|
-
return value;
|
|
88
|
-
},
|
|
89
|
-
push: function (key, ...values) {
|
|
90
|
-
this.promises.push(async () => {
|
|
91
|
-
let data = (await this.get(key)) || [];
|
|
92
|
-
data.push(...values);
|
|
93
|
-
await this.instance.setItem(key, data);
|
|
94
|
-
});
|
|
95
|
-
},
|
|
96
|
-
replace: function (values) {
|
|
97
|
-
this.promises.push(async () => {
|
|
98
|
-
for (let key in values) {
|
|
99
|
-
await this.instance.setItem(key, values[key]);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
},
|
|
103
|
-
shift: async function (key) {
|
|
104
|
-
let value, values = (await this.get(key)) || [];
|
|
105
|
-
value = values.shift();
|
|
106
|
-
this.promises.push(this.instance.setItem(key, values));
|
|
107
|
-
return value;
|
|
108
|
-
},
|
|
109
|
-
set: function (key, value) {
|
|
110
|
-
this.promises.push(this.instance.setItem(key, value));
|
|
111
|
-
},
|
|
112
|
-
settle: async function () {
|
|
113
|
-
await Promise.allSettled(this.promises.splice(0));
|
|
114
|
-
},
|
|
115
|
-
unshift: function (key, ...values) {
|
|
116
|
-
this.promises.push(async () => {
|
|
117
|
-
let data = (await this.get(key)) || [];
|
|
118
|
-
data.unshift(...values);
|
|
119
|
-
await this.instance.setItem(key, data);
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
exports.default = (options = {}) => new Store(options);
|