Created
October 18, 2016 20:18
-
-
Save patbonecrusher/942b8f470d11b28aafdbd6f27be3c6fd to your computer and use it in GitHub Desktop.
Given a list of oldname->newname mappings, it will rename object properties accordingly
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
export const renameKeys = R.curry((keysMap, obj) => { | |
return R.reduce((acc, key) => { | |
acc[keysMap[key] || key] = obj[key] | |
return acc | |
}, {}, R.keys(obj)) | |
}) | |
const permissionKeyMapping = { PermissionID: 'I', PermissionName: 'N' } | |
renameKeys(permissionKeyMapping, {PermissionID: 'a', PermissionName: 'b'}) // --> {I: 'a', N: 'b'} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment