@esportsplus/web-storage 0.0.5 → 0.0.8
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 +2 -2
- package/build/local/index.d.ts +2 -2
- package/build/local/index.js +15 -9
- package/package.json +30 -30
- package/src/index.ts +5 -5
- package/src/local/index.ts +19 -9
package/build/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import local from './local';
|
|
|
2
2
|
declare const _default: {
|
|
3
3
|
local: {
|
|
4
4
|
clear: () => void;
|
|
5
|
-
delete: (key: string) => void
|
|
5
|
+
delete: (key: string) => Promise<void>;
|
|
6
6
|
get: (key: string, value?: any) => Promise<any>;
|
|
7
7
|
has: (key: string) => Promise<boolean>;
|
|
8
8
|
prepend: (key: string, value: any) => Promise<void>;
|
|
@@ -10,7 +10,7 @@ declare const _default: {
|
|
|
10
10
|
replace: (values: {
|
|
11
11
|
[key: string]: any;
|
|
12
12
|
}) => void;
|
|
13
|
-
set: (key: string, value: any) => void
|
|
13
|
+
set: (key: string, value: any) => Promise<void>;
|
|
14
14
|
useIndexedDB: (options?: import("./local/types").Options) => void;
|
|
15
15
|
useLocalStorage: (options?: import("./local/types").Options) => void;
|
|
16
16
|
useOptions: (options?: import("./local/types").Options) => void;
|
package/build/local/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Options } from './types';
|
|
2
2
|
declare const _default: {
|
|
3
3
|
clear: () => void;
|
|
4
|
-
delete: (key: string) => void
|
|
4
|
+
delete: (key: string) => Promise<void>;
|
|
5
5
|
get: (key: string, value?: any) => Promise<any>;
|
|
6
6
|
has: (key: string) => Promise<boolean>;
|
|
7
7
|
prepend: (key: string, value: any) => Promise<void>;
|
|
@@ -9,7 +9,7 @@ declare const _default: {
|
|
|
9
9
|
replace: (values: {
|
|
10
10
|
[key: string]: any;
|
|
11
11
|
}) => void;
|
|
12
|
-
set: (key: string, value: any) => void
|
|
12
|
+
set: (key: string, value: any) => Promise<void>;
|
|
13
13
|
useIndexedDB: (options?: Options) => void;
|
|
14
14
|
useLocalStorage: (options?: Options) => void;
|
|
15
15
|
useOptions: (options?: Options) => void;
|
package/build/local/index.js
CHANGED
|
@@ -4,18 +4,18 @@ let cache = {}, driver = localforage.LOCALSTORAGE;
|
|
|
4
4
|
function init(options = {}) {
|
|
5
5
|
localforage.config(Object.assign({ name: 'store' }, options, { driver }));
|
|
6
6
|
}
|
|
7
|
-
function sync(key) {
|
|
7
|
+
async function sync(key) {
|
|
8
8
|
let root = (key.split('.')[0] || '');
|
|
9
|
-
localforage.setItem(root, dot.get(cache, root));
|
|
9
|
+
await localforage.setItem(root, dot.get(cache, root));
|
|
10
10
|
}
|
|
11
11
|
const clear = () => {
|
|
12
12
|
cache = {};
|
|
13
13
|
localforage.clear();
|
|
14
14
|
};
|
|
15
|
-
const del = (key) => {
|
|
15
|
+
const del = async (key) => {
|
|
16
16
|
dot.set(cache, key, undefined);
|
|
17
17
|
if (key.includes('.')) {
|
|
18
|
-
sync(key);
|
|
18
|
+
await sync(key);
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
21
|
localforage.removeItem(key);
|
|
@@ -39,11 +39,17 @@ const has = async (key) => {
|
|
|
39
39
|
if (dot.has(cache, key)) {
|
|
40
40
|
return true;
|
|
41
41
|
}
|
|
42
|
-
let
|
|
42
|
+
let k = key.split('.'), f = k.shift() || '', value = await localforage.getItem(f);
|
|
43
43
|
if (value !== null) {
|
|
44
|
-
set(
|
|
44
|
+
set(f, value);
|
|
45
|
+
if (Array.isArray(value) && k.length == 0) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
if (typeof value === 'object' && !Array.isArray(value) && value !== null) {
|
|
49
|
+
return dot.has(value, k.join('.'));
|
|
50
|
+
}
|
|
45
51
|
}
|
|
46
|
-
return
|
|
52
|
+
return false;
|
|
47
53
|
};
|
|
48
54
|
const prepend = async (key, value) => {
|
|
49
55
|
let values = await get(key, []);
|
|
@@ -66,9 +72,9 @@ const replace = (values) => {
|
|
|
66
72
|
set(key, values[key]);
|
|
67
73
|
}
|
|
68
74
|
};
|
|
69
|
-
const set = (key, value) => {
|
|
75
|
+
const set = async (key, value) => {
|
|
70
76
|
dot.set(cache, key, value);
|
|
71
|
-
sync(key);
|
|
77
|
+
await sync(key);
|
|
72
78
|
};
|
|
73
79
|
const useIndexedDB = (options = {}) => {
|
|
74
80
|
driver = localforage.INDEXEDDB;
|
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"author": "ICJR",
|
|
3
|
-
"dependencies": {
|
|
4
|
-
"@esportsplus/dot": "^0.0.3",
|
|
5
|
-
"localforage": "^1.10.0"
|
|
6
|
-
},
|
|
7
|
-
"description": "Web storage utility",
|
|
8
|
-
"devDependencies": {
|
|
9
|
-
"glob": "^7.1.7",
|
|
10
|
-
"node-polyfill-webpack-plugin": "^1.1.4",
|
|
11
|
-
"npm-run-all": "^4.1.5",
|
|
12
|
-
"ts-loader": "^9.2.6",
|
|
13
|
-
"tsc-alias": "^1.5.0",
|
|
14
|
-
"tsconfig-paths-webpack-plugin": "^3.5.2",
|
|
15
|
-
"typescript": "^4.5.2",
|
|
16
|
-
"webpack": "^5.64.4",
|
|
17
|
-
"webpack-cli": "^4.9.1"
|
|
18
|
-
},
|
|
19
|
-
"main": "./build/index.js",
|
|
20
|
-
"name": "@esportsplus/web-storage",
|
|
21
|
-
"private": false,
|
|
22
|
-
"scripts": {
|
|
23
|
-
"build": "tsc",
|
|
24
|
-
"-": "-",
|
|
25
|
-
"prepare": "npm run build",
|
|
26
|
-
"prepublishOnly": "npm run build"
|
|
27
|
-
},
|
|
28
|
-
"types": "./build/index.d.ts",
|
|
29
|
-
"version": "0.0.
|
|
30
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"author": "ICJR",
|
|
3
|
+
"dependencies": {
|
|
4
|
+
"@esportsplus/dot": "^0.0.3",
|
|
5
|
+
"localforage": "^1.10.0"
|
|
6
|
+
},
|
|
7
|
+
"description": "Web storage utility",
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"glob": "^7.1.7",
|
|
10
|
+
"node-polyfill-webpack-plugin": "^1.1.4",
|
|
11
|
+
"npm-run-all": "^4.1.5",
|
|
12
|
+
"ts-loader": "^9.2.6",
|
|
13
|
+
"tsc-alias": "^1.5.0",
|
|
14
|
+
"tsconfig-paths-webpack-plugin": "^3.5.2",
|
|
15
|
+
"typescript": "^4.5.2",
|
|
16
|
+
"webpack": "^5.64.4",
|
|
17
|
+
"webpack-cli": "^4.9.1"
|
|
18
|
+
},
|
|
19
|
+
"main": "./build/index.js",
|
|
20
|
+
"name": "@esportsplus/web-storage",
|
|
21
|
+
"private": false,
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc",
|
|
24
|
+
"-": "-",
|
|
25
|
+
"prepare": "npm run build",
|
|
26
|
+
"prepublishOnly": "npm run build"
|
|
27
|
+
},
|
|
28
|
+
"types": "./build/index.d.ts",
|
|
29
|
+
"version": "0.0.8"
|
|
30
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import local from './local';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export default { local };
|
|
5
|
-
export { local };
|
|
1
|
+
import local from './local';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export default { local };
|
|
5
|
+
export { local };
|
package/src/local/index.ts
CHANGED
|
@@ -11,10 +11,10 @@ function init(options: Options = {}): void {
|
|
|
11
11
|
localforage.config(Object.assign({ name: 'store' }, options, { driver }));
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
function sync(key: string) {
|
|
14
|
+
async function sync(key: string) {
|
|
15
15
|
let root = (key.split('.')[0] || '');
|
|
16
16
|
|
|
17
|
-
localforage.setItem(root, dot.get(cache, root));
|
|
17
|
+
await localforage.setItem(root, dot.get(cache, root));
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
|
|
@@ -23,11 +23,11 @@ const clear = () => {
|
|
|
23
23
|
localforage.clear();
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
const del = (key: string): void => {
|
|
26
|
+
const del = async (key: string): Promise<void> => {
|
|
27
27
|
dot.set(cache, key, undefined);
|
|
28
28
|
|
|
29
29
|
if (key.includes('.')) {
|
|
30
|
-
sync(key);
|
|
30
|
+
await sync(key);
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
33
|
localforage.removeItem(key);
|
|
@@ -59,13 +59,23 @@ const has = async (key: string): Promise<boolean> => {
|
|
|
59
59
|
return true;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
let
|
|
62
|
+
let k = key.split('.'),
|
|
63
|
+
f = k.shift() || '',
|
|
64
|
+
value = await localforage.getItem(f);
|
|
63
65
|
|
|
64
66
|
if (value !== null) {
|
|
65
|
-
set(
|
|
67
|
+
set(f, value);
|
|
68
|
+
|
|
69
|
+
if (Array.isArray(value) && k.length == 0) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (typeof value === 'object' && !Array.isArray(value) && value !== null) {
|
|
74
|
+
return dot.has(value, k.join('.'));
|
|
75
|
+
}
|
|
66
76
|
}
|
|
67
77
|
|
|
68
|
-
return
|
|
78
|
+
return false;
|
|
69
79
|
};
|
|
70
80
|
|
|
71
81
|
const prepend = async (key: string, value: any): Promise<void> => {
|
|
@@ -98,9 +108,9 @@ const replace = (values: { [key: string]: any }): void => {
|
|
|
98
108
|
}
|
|
99
109
|
};
|
|
100
110
|
|
|
101
|
-
const set = (key: string, value: any): void => {
|
|
111
|
+
const set = async (key: string, value: any): Promise<void> => {
|
|
102
112
|
dot.set(cache, key, value);
|
|
103
|
-
sync(key);
|
|
113
|
+
await sync(key);
|
|
104
114
|
};
|
|
105
115
|
|
|
106
116
|
const useIndexedDB = (options: Options = {}): void => {
|