pet-shop 0.1.2 → 0.1.3
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/index.js +23 -3
- package/package.json +7 -3
package/index.js
CHANGED
|
@@ -22,11 +22,13 @@ export function PetShop({ storage, namespace, json = false }) {
|
|
|
22
22
|
value: json
|
|
23
23
|
? function get(key) {
|
|
24
24
|
const raw = storage.getItem(`${namespace}.${key}`);
|
|
25
|
-
|
|
25
|
+
|
|
26
|
+
return raw === null ? undefined : safeParse(raw);
|
|
26
27
|
}
|
|
27
28
|
: function get(key) {
|
|
28
29
|
const raw = storage.getItem(`${namespace}.${key}`);
|
|
29
|
-
|
|
30
|
+
|
|
31
|
+
return raw === null ? undefined : raw;
|
|
30
32
|
},
|
|
31
33
|
},
|
|
32
34
|
set: {
|
|
@@ -46,6 +48,7 @@ export function PetShop({ storage, namespace, json = false }) {
|
|
|
46
48
|
if (typeof value !== 'string') {
|
|
47
49
|
throw new TypeError('The Value should be a string');
|
|
48
50
|
}
|
|
51
|
+
|
|
49
52
|
storage.setItem(`${namespace}.${key}`, value);
|
|
50
53
|
}
|
|
51
54
|
},
|
|
@@ -59,12 +62,15 @@ export function PetShop({ storage, namespace, json = false }) {
|
|
|
59
62
|
rawKeys: {
|
|
60
63
|
get() {
|
|
61
64
|
const keys = [];
|
|
65
|
+
|
|
62
66
|
for (let i = 0; i < storage.length; i += 1) {
|
|
63
67
|
const key = storage.key(i);
|
|
68
|
+
|
|
64
69
|
if (key.startsWith(`${namespace}.`)) {
|
|
65
70
|
keys.push(key);
|
|
66
71
|
}
|
|
67
72
|
}
|
|
73
|
+
|
|
68
74
|
return keys;
|
|
69
75
|
},
|
|
70
76
|
},
|
|
@@ -85,7 +91,6 @@ export function PetShop({ storage, namespace, json = false }) {
|
|
|
85
91
|
valueOf: {
|
|
86
92
|
enumerable: true,
|
|
87
93
|
value: function valueOf() {
|
|
88
|
-
// eslint-disable-next-line unicorn/prefer-object-from-entries
|
|
89
94
|
return this.keys.reduce(
|
|
90
95
|
(io, key) => ({ [key]: this.get(key), ...io }),
|
|
91
96
|
{},
|
|
@@ -115,3 +120,18 @@ export function PetShop({ storage, namespace, json = false }) {
|
|
|
115
120
|
},
|
|
116
121
|
);
|
|
117
122
|
}
|
|
123
|
+
|
|
124
|
+
export function smart(store, key) {
|
|
125
|
+
return {
|
|
126
|
+
get() {
|
|
127
|
+
return store.get(key);
|
|
128
|
+
},
|
|
129
|
+
set(value) {
|
|
130
|
+
if (value !== null && value !== undefined) {
|
|
131
|
+
store.set(key, value);
|
|
132
|
+
} else {
|
|
133
|
+
store.remove(key);
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pet-shop",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "A simple wrapper of Web Storage API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -28,5 +28,9 @@
|
|
|
28
28
|
"url": "https://github.com/airkro/frontend-toolkit/issues"
|
|
29
29
|
},
|
|
30
30
|
"main": "index.js",
|
|
31
|
-
"type": "module"
|
|
32
|
-
|
|
31
|
+
"type": "module",
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public",
|
|
34
|
+
"registry": "https://registry.npmjs.org/"
|
|
35
|
+
}
|
|
36
|
+
}
|