Last active
January 22, 2021 16:37
-
-
Save jsheffers/0cab09a6ebd30c80cd6498b917383dea to your computer and use it in GitHub Desktop.
Santize Redux Actions (by property)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Recursive function to find keys, and clear out sensitive data. | |
export const sanitizeReduxActions = (theObject, exclusions) => { | |
var result = null; | |
if (theObject instanceof Array) { | |
for (var i = 0; i < theObject.length; i++) { | |
result = sanitizeReduxActions(theObject[i], exclusions); | |
if (result) { | |
break; | |
} | |
} | |
} else { | |
for (var prop in theObject) { | |
// If prop is in exclusions list, alter the value | |
if (exclusions.includes(prop)) { | |
theObject[prop] = "*"; | |
} | |
if ( | |
theObject[prop] instanceof Object || | |
theObject[prop] instanceof Array | |
) { | |
// Trigger another recursion if value is array/object | |
result = sanitizeReduxActions(theObject[prop], exclusions); | |
if (result) { | |
break; | |
} | |
} | |
} | |
return theObject; | |
} | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment