Skip to content

Instantly share code, notes, and snippets.

@sibelius
Last active November 19, 2019 12:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sibelius/8d3069ba76e80c68c574cf499c73e283 to your computer and use it in GitHub Desktop.
Save sibelius/8d3069ba76e80c68c574cf499c73e283 to your computer and use it in GitHub Desktop.
filterPassword from objects before logging them
export const filterPassword = (obj: object) => {
return Object.keys(obj).reduce((acc, key) => {
const value = obj[key];
if (Array.isArray(value)) {
return {
...acc,
[key]: value,
}
}
if (typeof value === 'object') {
const sanitize = filterPassword(value);
return {
...acc,
[key]: sanitize,
};
}
if (key === 'password') {
return {
...acc,
[key]: '********',
};
}
return {
...acc,
[key]: value,
};
}, {});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment