Skip to content

Instantly share code, notes, and snippets.

@jaredgorski
Last active December 5, 2019 00:49
Show Gist options
  • Save jaredgorski/0f7ec55d579b1f519498275d1a957b73 to your computer and use it in GitHub Desktop.
Save jaredgorski/0f7ec55d579b1f519498275d1a957b73 to your computer and use it in GitHub Desktop.
normalizer
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