[d24f17c] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | exports.__esModule = true;
|
---|
| 4 | exports["default"] = void 0;
|
---|
| 5 | var _ramda = require("ramda");
|
---|
| 6 | var _renameKeys2 = _interopRequireDefault(require("./renameKeys"));
|
---|
| 7 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 8 | 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); }
|
---|
| 9 | 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; }
|
---|
| 10 | function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
---|
| 11 | 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); }
|
---|
| 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 | */
|
---|
| 36 | var renameKey = (0, _ramda.curry)(function (oldKey, newKey, obj) {
|
---|
| 37 | return (0, _renameKeys2["default"])(_defineProperty({}, oldKey, newKey), obj);
|
---|
| 38 | });
|
---|
| 39 | var _default = renameKey;
|
---|
| 40 | exports["default"] = _default; |
---|