diff --git a/README.md b/README.md index b8b021b..afb28a8 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ interface ITransformArgs { } ``` -As an example, one may see how [whitelists](https://github.com/agilgur5/mst-persist/blob/229fd2b1b472ea6a7912a5a06fa079a65e3ba6fa/src/whitelistTransform.ts#L7-L14) and [blacklists](https://github.com/agilgur5/mst-persist/blob/229fd2b1b472ea6a7912a5a06fa079a65e3ba6fa/src/blacklistTransform.ts#L7-L14) are implemented internally as transforms. +As an example, one may see how [whitelists](https://github.com/agilgur5/mst-persist/blob/9ba76aaf455f42e249dc855d66349351148a17da/src/whitelistTransform.ts#L7-L12) and [blacklists](https://github.com/agilgur5/mst-persist/blob/9ba76aaf455f42e249dc855d66349351148a17da/src/blacklistTransform.ts#L7-L12) are implemented internally as transforms. #### Transform Ordering diff --git a/src/blacklistTransform.ts b/src/blacklistTransform.ts index b390f91..34b265e 100644 --- a/src/blacklistTransform.ts +++ b/src/blacklistTransform.ts @@ -1,12 +1,10 @@ import { arrToDict } from './utils' import { ITransform } from './index' -export function blacklistKeys (blacklist?: Array): ITransform { +export function blacklistKeys (blacklist: Array): ITransform { const blacklistDict = arrToDict(blacklist) return {toStorage: function blacklistTransform (snapshot) { - if (!blacklist) { return snapshot } - Object.keys(snapshot).forEach((key) => { if (blacklistDict[key]) { delete snapshot[key] } }) diff --git a/src/utils.ts b/src/utils.ts index f35d13c..6a53bfd 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,8 +2,7 @@ export type StrToAnyMap = {[key: string]: any} export type StrToBoolMap = {[key: string]: boolean} -export function arrToDict (arr?: Array): StrToBoolMap { - if (!arr) { return {} } +export function arrToDict (arr: Array): StrToBoolMap { return arr.reduce((dict: StrToBoolMap, elem) => { dict[elem] = true return dict diff --git a/src/whitelistTransform.ts b/src/whitelistTransform.ts index 926e623..fc45758 100644 --- a/src/whitelistTransform.ts +++ b/src/whitelistTransform.ts @@ -1,12 +1,10 @@ import { arrToDict } from './utils' import { ITransform } from './index' -export function whitelistKeys (whitelist?: Array): ITransform { +export function whitelistKeys (whitelist: Array): ITransform { const whitelistDict = arrToDict(whitelist) return {toStorage: function whitelistTransform (snapshot) { - if (!whitelist) { return snapshot } - Object.keys(snapshot).forEach((key) => { if (!whitelistDict[key]) { delete snapshot[key] } })