source: node_modules/ramda-adjunct/lib/renameKeysWith.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.2 KB
Line 
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5var _ramda = require("ramda");
6/**
7 * Creates a new object with the own properties of the provided object, but the
8 * keys renamed according to logic of renaming function.
9 *
10 * Keep in mind that in the case of keys conflict is behaviour undefined and
11 * the result may vary between various JS engines!
12 *
13 * @func renameKeysWith
14 * @memberOf RA
15 * @since {@link https://char0n.github.io/ramda-adjunct/1.5.0|v1.5.0}
16 * @category Object
17 * @sig (a -> b) -> {a: *} -> {b: *}
18 * @param {Function} fn Function that renames the keys
19 * @param {!Object} obj Provided object
20 * @return {!Object} New object with renamed keys
21 * @see {@link https://github.com/ramda/ramda/wiki/Cookbook#rename-keys-of-an-object-by-a-function|Ramda Cookbook}, {@link RA.renameKeys|renameKeys}
22 * @example
23 *
24 * RA.renameKeysWith(R.concat('a'), { A: 1, B: 2, C: 3 }) //=> { aA: 1, aB: 2, aC: 3 }
25 */
26var renameKeysWith = (0, _ramda.curry)(function (fn, obj) {
27 return (0, _ramda.pipe)(_ramda.toPairs, (0, _ramda.map)((0, _ramda.over)((0, _ramda.lensIndex)(0), fn)), _ramda.fromPairs)(obj);
28});
29var _default = renameKeysWith;
30exports["default"] = _default;
Note: See TracBrowser for help on using the repository browser.