Skip to content

Commit 28473e6

Browse files
committed
(optim): return early if white|blacklist doesn't exist
- more importantly, makes the logic a little simpler / easier to read
1 parent d1584de commit 28473e6

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/blacklistTransform.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ export function blacklistKeys (blacklist?: Array<string>): ITransform {
55
const blacklistDict = arrToDict(blacklist)
66

77
return {toStorage: function whitelistTransform (snapshot) {
8+
if (!blacklist) { return snapshot }
9+
810
Object.keys(snapshot).forEach((key) => {
9-
if (blacklist && blacklistDict[key]) {
10-
delete snapshot[key]
11-
}
11+
if (blacklistDict[key]) { delete snapshot[key] }
1212
})
1313
return snapshot
1414
}}

src/whitelistTransform.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ export function whitelistKeys (whitelist?: Array<string>): ITransform {
55
const whitelistDict = arrToDict(whitelist)
66

77
return {toStorage: function whitelistTransform (snapshot) {
8+
if (!whitelist) { return snapshot }
9+
810
Object.keys(snapshot).forEach((key) => {
9-
if (whitelist && !whitelistDict[key]) {
10-
delete snapshot[key]
11-
}
11+
if (!whitelistDict[key]) { delete snapshot[key] }
1212
})
1313
return snapshot
1414
}}

0 commit comments

Comments
 (0)