Created
August 17, 2021 19:27
-
-
Save harentius/e0d8d1c4d2fa4c00a01c37869b115d95 to your computer and use it in GitHub Desktop.
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
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