source: node_modules/ramda-adjunct/es/renameKeyWith.js@ d24f17c

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

Initial commit

  • Property mode set to 100644
File size: 1.0 KB
Line 
1import { curry, equals, when } from 'ramda';
2import renameKeysWith from './renameKeysWith';
3
4/**
5 * Creates a new object with the own properties of the provided object, but the
6 * key `key` renamed according to logic of renaming function.
7 *
8 * Keep in mind that in case the new key name already existed on the object,
9 * the behaviour is undefined and the result may vary between various JS engines!
10 *
11 * @func renameKeyWith
12 * @memberOf RA
13 * @since {@link https://char0n.github.io/ramda-adjunct/2.29.0|v2.29.0}
14 * @category Object
15 * @sig (k -> k) -> k -> {k: v} -> {k: v}
16 * @param {Function} fn Function that renames the keys
17 * @param {!string} key Key to rename
18 * @param {!Object} obj Provided object
19 * @return {!Object} New object with renamed key
20 * @see {@link RA.renameKeysWith|renameKeysWith}
21 * @example
22 *
23 * RA.renameKeyWith(R.concat('a'), 'A', { A: 1 }) //=> { aA: 1 }
24 */
25var renameKeyWith = curry(function (fn, key, obj) {
26 return renameKeysWith(when(equals(key), fn), obj);
27});
28export default renameKeyWith;
Note: See TracBrowser for help on using the repository browser.