Skip to content

Instantly share code, notes, and snippets.

@DmitrySoshnikov
Created March 16, 2019 20:35
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 DmitrySoshnikov/a0ce221eb2419923e46f0dc5a7e9d684 to your computer and use it in GitHub Desktop.
Save DmitrySoshnikov/a0ce221eb2419923e46f0dc5a7e9d684 to your computer and use it in GitHub Desktop.
/**
* Filter object properties.
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* MIT Style license, 2019
*/
const filterProps = (
[p1, p2, p3],
{
[p1]: _p1,
[p2]: _p2,
[p3]: _p3,
...toKeep
}
) => toKeep;
const data = {
password: 'querty',
accessToken: 'secret',
userID: 13,
userName: 'Yrtimd'
};
const dataToLog = filterProps(
['password', 'accessToken'],
data,
);
console.log(dataToLog); // {userID: 13, userName: 'Yrtimd'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment