@esportsplus/web-storage 0.1.2 → 0.1.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/build/index.d.ts CHANGED
@@ -19,7 +19,7 @@ declare const _default: {
19
19
  push(key: string, ...values: any[]): void;
20
20
  replace(values: {
21
21
  [key: string]: any;
22
- }): void;
22
+ }, whitelist?: string[]): void;
23
23
  shift(key: string): Promise<any>;
24
24
  set(key: string, value: any): void;
25
25
  sync(): Promise<void>;
@@ -18,7 +18,7 @@ declare class Store {
18
18
  push(key: string, ...values: any[]): void;
19
19
  replace(values: {
20
20
  [key: string]: any;
21
- }): void;
21
+ }, whitelist?: string[]): void;
22
22
  shift(key: string): Promise<any>;
23
23
  set(key: string, value: any): void;
24
24
  sync(): Promise<void>;
@@ -38,6 +38,9 @@ class Store {
38
38
  return this.instance.clear();
39
39
  }
40
40
  delete(...keys) {
41
+ if (!keys.length) {
42
+ return;
43
+ }
41
44
  this.promises.push(async () => {
42
45
  for (let i = 0, n = keys.length; i < n; i++) {
43
46
  await this.instance.removeItem(keys[i]);
@@ -102,13 +105,29 @@ class Store {
102
105
  return value;
103
106
  }
104
107
  push(key, ...values) {
108
+ if (!values.length) {
109
+ return;
110
+ }
105
111
  this.promises.push(async () => {
106
112
  let data = (await this.get(key)) || [];
107
113
  data.push(...values);
108
114
  await this.instance.setItem(key, data);
109
115
  });
110
116
  }
111
- replace(values) {
117
+ replace(values, whitelist = []) {
118
+ if (whitelist.length) {
119
+ let whitelisted = {};
120
+ for (let i = 0, n = whitelist.length; i < n; i++) {
121
+ if (!values[whitelist[i]]) {
122
+ continue;
123
+ }
124
+ whitelisted[whitelist[i]] = values[whitelist[i]];
125
+ }
126
+ values = whitelisted;
127
+ }
128
+ if (!Object.keys(values).length) {
129
+ return;
130
+ }
112
131
  this.promises.push(async () => {
113
132
  for (let key in values) {
114
133
  await this.instance.setItem(key, values[key]);
@@ -128,6 +147,9 @@ class Store {
128
147
  await Promise.allSettled(this.promises.splice(0));
129
148
  }
130
149
  unshift(key, ...values) {
150
+ if (!values.length) {
151
+ return;
152
+ }
131
153
  this.promises.push(async () => {
132
154
  let data = (await this.get(key)) || [];
133
155
  data.unshift(...values);
package/package.json CHANGED
@@ -23,5 +23,5 @@
23
23
  "prepublishOnly": "npm run build"
24
24
  },
25
25
  "types": "./build/index.d.ts",
26
- "version": "0.1.2"
26
+ "version": "0.1.4"
27
27
  }
@@ -49,6 +49,10 @@ class Store {
49
49
  }
50
50
 
51
51
  delete(...keys: string[]): void {
52
+ if (!keys.length) {
53
+ return;
54
+ }
55
+
52
56
  this.promises.push(async () => {
53
57
  for (let i = 0, n = keys.length; i < n; i++) {
54
58
  await this.instance.removeItem(keys[i]);
@@ -138,6 +142,10 @@ class Store {
138
142
  }
139
143
 
140
144
  push(key: string, ...values: any[]): void {
145
+ if (!values.length) {
146
+ return;
147
+ }
148
+
141
149
  this.promises.push(async () => {
142
150
  let data = (await this.get(key)) || [];
143
151
 
@@ -147,7 +155,25 @@ class Store {
147
155
  });
148
156
  }
149
157
 
150
- replace(values: { [key: string]: any }): void {
158
+ replace(values: { [key: string]: any }, whitelist: string[] = []): void {
159
+ if (whitelist.length) {
160
+ let whitelisted: { [key: string]: any } = {};
161
+
162
+ for (let i = 0, n = whitelist.length; i < n; i++) {
163
+ if (!values[whitelist[i]]) {
164
+ continue;
165
+ }
166
+
167
+ whitelisted[whitelist[i]] = values[whitelist[i]];
168
+ }
169
+
170
+ values = whitelisted;
171
+ }
172
+
173
+ if (!Object.keys(values).length) {
174
+ return;
175
+ }
176
+
151
177
  this.promises.push(async () => {
152
178
  for (let key in values) {
153
179
  await this.instance.setItem(key, values[key])
@@ -175,6 +201,10 @@ class Store {
175
201
  }
176
202
 
177
203
  unshift(key: string, ...values: any[]): void {
204
+ if (!values.length) {
205
+ return;
206
+ }
207
+
178
208
  this.promises.push(async () => {
179
209
  let data = (await this.get(key)) || [];
180
210