Skip to content

Instantly share code, notes, and snippets.

@jsheffers
Last active January 22, 2021 16:37
Show Gist options
  • Save jsheffers/0cab09a6ebd30c80cd6498b917383dea to your computer and use it in GitHub Desktop.
Save jsheffers/0cab09a6ebd30c80cd6498b917383dea to your computer and use it in GitHub Desktop.
Santize Redux Actions (by property)
// 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