source: node_modules/ramda-adjunct/lib/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.4 KB
Line 
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5var _ramda = require("ramda");
6var _renameKeys2 = _interopRequireDefault(require("./renameKeys"));
7function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
8function _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); }
9function _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; }
10function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
11function _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); }
12/**
13 * Creates a new object with the own properties of the provided object, but a
14 * single key is renamed from `oldKey` to `newKey`.
15 *
16 * Keep in mind that in the case of keys conflict is behavior undefined and
17 * the result may vary between various JS engines!
18 *
19 * @func renameKey
20 * @memberOf RA
21 * @since {@link https://char0n.github.io/ramda-adjunct/4.1.0|v4.1.0}
22 * @category Object
23 * @sig (String a, String b) => a -> b -> {a: *} -> {b: *}
24 * @param {!string} oldKey
25 * @param {!string} newKey
26 * @param {!Object} obj
27 * @return {!Object} New object with renamed key
28 * @see {@link https://github.com/ramda/ramda/wiki/Cookbook#rename-key-of-an-object|Ramda Cookbook}, {@link RA.renameKeyWith|renameKeyWith}
29 * @example
30 *
31 * const input = { firstName: 'Elisia', age: 22, type: 'human' };
32 *
33 * RA.renameKey('firstName', 'name')(input);
34 * //=> { name: 'Elisia', age: 22, type: 'human' }
35 */
36var renameKey = (0, _ramda.curry)(function (oldKey, newKey, obj) {
37 return (0, _renameKeys2["default"])(_defineProperty({}, oldKey, newKey), obj);
38});
39var _default = renameKey;
40exports["default"] = _default;
Note: See TracBrowser for help on using the repository browser.