source: node_modules/ramda-adjunct/es/renameKey.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 2.2 KB
Line 
1function _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); }
2function _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; }
3function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
4function _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); }
5import { curry } from 'ramda';
6import 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 */
32var renameKey = curry(function (oldKey, newKey, obj) {
33 return renameKeys(_defineProperty({}, oldKey, newKey), obj);
34});
35export default renameKey;
Note: See TracBrowser for help on using the repository browser.