Last active
December 5, 2019 00:49
-
-
Save jaredgorski/0f7ec55d579b1f519498275d1a957b73 to your computer and use it in GitHub Desktop.
normalizer
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
const normalize = (input, normalizer) => { | |
return Object.keys(input).reduce((obj, curr) => { | |
if (input[curr] instanceof Object && !Array.isArray(input[curr])) { | |
obj[curr] = normalize(input[curr], normalizer[curr]); | |
} else if (Object.prototype.hasOwnProperty.call(normalizer, curr)) { | |
obj[curr] = normalizer[curr](input[curr]); | |
} else { | |
obj[curr] = input[curr]; | |
} | |
return obj; | |
}, {}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment