Skip to content

Instantly share code, notes, and snippets.

@patbonecrusher
Created October 18, 2016 20:18
Show Gist options
  • Save patbonecrusher/942b8f470d11b28aafdbd6f27be3c6fd to your computer and use it in GitHub Desktop.
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
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