We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0945da5 commit c224bfeCopy full SHA for c224bfe
lib/utils.js
@@ -964,6 +964,29 @@ exports.each = function(arr, fn) {
964
}
965
};
966
967
+/**
968
+ * Rename an object key, while preserving its position in the object
969
+ *
970
+ * @param {Object} oldObj
971
+ * @param {String|Number} oldKey
972
+ * @param {String|Number} newKey
973
+ * @api private
974
+ */
975
+exports.renameObjKey = function (oldObj, oldKey, newKey) {
976
+ const keys = Object.keys(oldObj);
977
+ return keys.reduce(
978
+ (acc, val) => {
979
+ if (val === oldKey) {
980
+ acc[newKey] = oldObj[oldKey];
981
+ } else {
982
+ acc[val] = oldObj[val];
983
+ }
984
+ return acc;
985
+ },
986
+ {} as Record<string, unknown>
987
+ );
988
+}
989
+
990
/*!
991
* ignore
992
*/
0 commit comments