1 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
---|
2 | function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
---|
3 | function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
---|
4 | function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
---|
5 | import { curry } from 'ramda';
|
---|
6 | import renameKeys from './renameKeys';
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * Creates a new object with the own properties of the provided object, but a
|
---|
10 | * single key is renamed from `oldKey` to `newKey`.
|
---|
11 | *
|
---|
12 | * Keep in mind that in the case of keys conflict is behavior undefined and
|
---|
13 | * the result may vary between various JS engines!
|
---|
14 | *
|
---|
15 | * @func renameKey
|
---|
16 | * @memberOf RA
|
---|
17 | * @since {@link https://char0n.github.io/ramda-adjunct/4.1.0|v4.1.0}
|
---|
18 | * @category Object
|
---|
19 | * @sig (String a, String b) => a -> b -> {a: *} -> {b: *}
|
---|
20 | * @param {!string} oldKey
|
---|
21 | * @param {!string} newKey
|
---|
22 | * @param {!Object} obj
|
---|
23 | * @return {!Object} New object with renamed key
|
---|
24 | * @see {@link https://github.com/ramda/ramda/wiki/Cookbook#rename-key-of-an-object|Ramda Cookbook}, {@link RA.renameKeyWith|renameKeyWith}
|
---|
25 | * @example
|
---|
26 | *
|
---|
27 | * const input = { firstName: 'Elisia', age: 22, type: 'human' };
|
---|
28 | *
|
---|
29 | * RA.renameKey('firstName', 'name')(input);
|
---|
30 | * //=> { name: 'Elisia', age: 22, type: 'human' }
|
---|
31 | */
|
---|
32 | var renameKey = curry(function (oldKey, newKey, obj) {
|
---|
33 | return renameKeys(_defineProperty({}, oldKey, newKey), obj);
|
---|
34 | });
|
---|
35 | export default renameKey; |
---|