Skip to content

Instantly share code, notes, and snippets.

@mturnwall
Last active October 14, 2018 18:08
Show Gist options
  • Save mturnwall/f07537b403f6b1f587faa56b1b3a6e55 to your computer and use it in GitHub Desktop.
Save mturnwall/f07537b403f6b1f587faa56b1b3a6e55 to your computer and use it in GitHub Desktop.
Rename Object Property
/**
* 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