source: node_modules/ramda-adjunct/src/copyKeys.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: 958 bytes
Line 
1import { curryN } from 'ramda';
2
3import renameKeys from './renameKeys';
4
5/**
6 * Creates a new object with the own properties of the provided object, and the
7 * keys copied according to the keysMap object as `{oldKey: newKey}`.
8 * When no key from the keysMap is found, then a shallow clone of an object is returned.
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 copyKeys
14 * @memberOf RA
15 * @category Object
16 * @sig {a: b} -> {a: *} -> {b: *}
17 * @param {!Object} keysMap
18 * @param {!Object} obj
19 * @return {!Object} New object with copied keys
20 * @see {@link RA.renameKeys|renameKeys}
21 * @example
22 *
23 * copyKeys({ a: 'b' }, { a: true }); //=> { a: true, b: true }
24 * copyKeys({ a: 'b' }, { a: true, b: false }); //=> { a: true, b: true }
25 */
26const copyKeys = curryN(2, (keysMap, obj) => ({
27 ...obj,
28 ...renameKeys(keysMap, obj),
29}));
30
31export default copyKeys;
Note: See TracBrowser for help on using the repository browser.