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:
909 bytes
|
Line | |
---|
1 | import { curryN, converge, mergeRight, dissocPath, pathOr } from 'ramda';
|
---|
2 |
|
---|
3 | /**
|
---|
4 | * Spreads object under property path onto provided object.
|
---|
5 | * It's like {@link RA.flattenPath|flattenPath}, but removes object under the property path.
|
---|
6 | *
|
---|
7 | * @func spreadPath
|
---|
8 | * @memberOf RA
|
---|
9 | * @since {@link https://char0n.github.io/ramda-adjunct/1.19.0|v1.19.0}
|
---|
10 | * @category Object
|
---|
11 | * @typedef Idx = String | Int
|
---|
12 | * @sig [Idx] -> {k: v} -> {k: v}
|
---|
13 | * @param {!Array.<string|number>} path The property path to spread
|
---|
14 | * @param {!Object} obj The provided object
|
---|
15 | * @return {!Object} The result of the spread
|
---|
16 | * @see {@link RA.spreadProp|spreadProp}, {@link RA.flattenPath|flattenPath}
|
---|
17 | * @example
|
---|
18 | *
|
---|
19 | * RA.spreadPath(
|
---|
20 | * ['b1', 'b2'],
|
---|
21 | * { a: 1, b1: { b2: { c: 3, d: 4 } } }
|
---|
22 | * ); // => { a: 1, c: 3, d: 4, b1: {} };
|
---|
23 | */
|
---|
24 | const spreadPath = curryN(2, converge(mergeRight, [dissocPath, pathOr({})]));
|
---|
25 |
|
---|
26 | export default spreadPath;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.