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