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