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.1 KB
|
Rev | Line | |
---|
[d24f17c] | 1 | import { curry } from 'ramda';
|
---|
| 2 |
|
---|
| 3 | import renameKeys from './renameKeys';
|
---|
| 4 |
|
---|
| 5 | /**
|
---|
| 6 | * Creates a new object with the own properties of the provided object, but a
|
---|
| 7 | * single key is renamed from `oldKey` to `newKey`.
|
---|
| 8 | *
|
---|
| 9 | * Keep in mind that in the case of keys conflict is behavior undefined and
|
---|
| 10 | * the result may vary between various JS engines!
|
---|
| 11 | *
|
---|
| 12 | * @func renameKey
|
---|
| 13 | * @memberOf RA
|
---|
| 14 | * @since {@link https://char0n.github.io/ramda-adjunct/4.1.0|v4.1.0}
|
---|
| 15 | * @category Object
|
---|
| 16 | * @sig (String a, String b) => a -> b -> {a: *} -> {b: *}
|
---|
| 17 | * @param {!string} oldKey
|
---|
| 18 | * @param {!string} newKey
|
---|
| 19 | * @param {!Object} obj
|
---|
| 20 | * @return {!Object} New object with renamed key
|
---|
| 21 | * @see {@link https://github.com/ramda/ramda/wiki/Cookbook#rename-key-of-an-object|Ramda Cookbook}, {@link RA.renameKeyWith|renameKeyWith}
|
---|
| 22 | * @example
|
---|
| 23 | *
|
---|
| 24 | * const input = { firstName: 'Elisia', age: 22, type: 'human' };
|
---|
| 25 | *
|
---|
| 26 | * RA.renameKey('firstName', 'name')(input);
|
---|
| 27 | * //=> { name: 'Elisia', age: 22, type: 'human' }
|
---|
| 28 | */
|
---|
| 29 | const renameKey = curry((oldKey, newKey, obj) =>
|
---|
| 30 | renameKeys({ [oldKey]: newKey }, obj)
|
---|
| 31 | );
|
---|
| 32 |
|
---|
| 33 | export default renameKey;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.