monoidentity 0.0.3 → 0.0.4
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/dist/storage-private-local.js +12 -19
- package/package.json +1 -1
|
@@ -1,31 +1,24 @@
|
|
|
1
|
-
const prefix = "monoidentity";
|
|
2
|
-
const prefixed = (key) => `${prefix}
|
|
1
|
+
const prefix = "monoidentity/";
|
|
2
|
+
const prefixed = (key) => `${prefix}${key}`;
|
|
3
3
|
const unprefixed = (key) => {
|
|
4
|
-
if (!key.startsWith(
|
|
4
|
+
if (!key.startsWith(prefix))
|
|
5
5
|
throw new Error("Key is not prefixed");
|
|
6
|
-
return key.slice(prefix.length
|
|
6
|
+
return key.slice(prefix.length);
|
|
7
7
|
};
|
|
8
8
|
const target = {};
|
|
9
9
|
const get = (_, key) => {
|
|
10
|
-
if (typeof key
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return undefined;
|
|
10
|
+
if (typeof key != "string")
|
|
11
|
+
return undefined;
|
|
12
|
+
const value = localStorage.getItem(prefixed(key));
|
|
13
|
+
if (value == null)
|
|
14
|
+
return undefined;
|
|
15
|
+
return value;
|
|
22
16
|
};
|
|
23
17
|
export const init = () => new Proxy(target, {
|
|
24
18
|
get,
|
|
25
19
|
set(_, key, value) {
|
|
26
20
|
if (typeof key == "string") {
|
|
27
|
-
|
|
28
|
-
localStorage.setItem(prefixed(key), serialized);
|
|
21
|
+
localStorage.setItem(prefixed(key), value);
|
|
29
22
|
return true;
|
|
30
23
|
}
|
|
31
24
|
return false;
|
|
@@ -44,7 +37,7 @@ export const init = () => new Proxy(target, {
|
|
|
44
37
|
const keys = [];
|
|
45
38
|
for (let i = 0; i < localStorage.length; i++) {
|
|
46
39
|
const key = localStorage.key(i);
|
|
47
|
-
if (key && key.startsWith(
|
|
40
|
+
if (key && key.startsWith(prefix)) {
|
|
48
41
|
keys.push(unprefixed(key));
|
|
49
42
|
}
|
|
50
43
|
}
|