Last active
October 14, 2018 18:08
-
-
Save mturnwall/f07537b403f6b1f587faa56b1b3a6e55 to your computer and use it in GitHub Desktop.
Rename Object Property
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
/** | |
* Change the key for a giving object | |
* | |
* @param {string} oldKey - the key (property) you want to change | |
* @param {string} newKey - the new key | |
* @param {Object} old - object that needs to be changed | |
* | |
* @returns {Object} | |
*/ | |
export default function (oldKey, newKey, {[oldKey]: old, ...rest}) { | |
return { | |
[newKey]: old, | |
...rest, | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment