Skip to content

Instantly share code, notes, and snippets.

@harentius
Created August 17, 2021 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harentius/e0d8d1c4d2fa4c00a01c37869b115d95 to your computer and use it in GitHub Desktop.
Save harentius/e0d8d1c4d2fa4c00a01c37869b115d95 to your computer and use it in GitHub Desktop.
import { get, set } from 'lodash';
const remapData = (
from: {[key: string]: any},
remapConfig: { [key: string]: string},
to: {} = {},
) => {
Object.entries(remapConfig).forEach(([fromPath, toPath]) => {
const value = get(from, fromPath, undefined);
if (value === undefined) {
return;
}
set(to, toPath, value);
});
return to;
};
export default remapData;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment