@esportsplus/web-storage 0.1.3 → 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>;
@@ -114,7 +114,17 @@ class Store {
114
114
  await this.instance.setItem(key, data);
115
115
  });
116
116
  }
117
- 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
+ }
118
128
  if (!Object.keys(values).length) {
119
129
  return;
120
130
  }
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.3"
26
+ "version": "0.1.4"
27
27
  }
@@ -155,7 +155,21 @@ class Store {
155
155
  });
156
156
  }
157
157
 
158
- 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
+
159
173
  if (!Object.keys(values).length) {
160
174
  return;
161
175
  }