source: node_modules/ramda-adjunct/lib/renameKeys.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: 1.6 KB
RevLine 
[d24f17c]1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5var _ramda = require("ramda");
6var _renameKeysWith = _interopRequireDefault(require("./renameKeysWith"));
7function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
8var valueOrKey = function valueOrKey(keysMap) {
9 return function (key) {
10 if ((0, _ramda.has)(key, keysMap)) {
11 return keysMap[key];
12 }
13 return key;
14 };
15};
16
17/**
18 * Creates a new object with the own properties of the provided object, but the
19 * keys renamed according to the keysMap object as `{oldKey: newKey}`.
20 * When some key is not found in the keysMap, then it's passed as-is.
21 *
22 * Keep in mind that in the case of keys conflict is behaviour undefined and
23 * the result may vary between various JS engines!
24 *
25 * @func renameKeys
26 * @memberOf RA
27 * @since {@link https://char0n.github.io/ramda-adjunct/1.5.0|v1.5.0}
28 * @category Object
29 * @sig {a: b} -> {a: *} -> {b: *}
30 * @param {!Object} keysMap
31 * @param {!Object} obj
32 * @return {!Object} New object with renamed keys
33 * @see {@link https://github.com/ramda/ramda/wiki/Cookbook#rename-keys-of-an-object|Ramda Cookbook}, {@link RA.renameKeysWith|renameKeysWith}
34 * @example
35 *
36 * const input = { firstName: 'Elisia', age: 22, type: 'human' };
37 *
38 * RA.renameKeys({ firstName: 'name', type: 'kind', foo: 'bar' })(input);
39 * //=> { name: 'Elisia', age: 22, kind: 'human' }
40 */
41var renameKeys = (0, _ramda.curry)(function (keysMap, obj) {
42 return (0, _renameKeysWith["default"])(valueOrKey(keysMap), obj);
43});
44var _default = renameKeys;
45exports["default"] = _default;
Note: See TracBrowser for help on using the repository browser.