Last active
November 19, 2019 12:03
-
-
Save sibelius/8d3069ba76e80c68c574cf499c73e283 to your computer and use it in GitHub Desktop.
filterPassword from objects before logging them
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
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