1 | "use strict";
|
---|
2 |
|
---|
3 | exports.__esModule = true;
|
---|
4 | exports["default"] = void 0;
|
---|
5 | var _ramda = require("ramda");
|
---|
6 | /**
|
---|
7 | * Flattens a property path so that its fields are spread out into the provided object.
|
---|
8 | * It's like {@link RA.spreadPath|spreadPath}, but preserves object under the property path.
|
---|
9 | *
|
---|
10 | * @func flattenPath
|
---|
11 | * @memberOf RA
|
---|
12 | * @since {@link https://char0n.github.io/ramda-adjunct/1.19.0|v1.19.0}
|
---|
13 | * @category Object
|
---|
14 | * @typedef Idx = String | Int
|
---|
15 | * @sig [Idx] -> {k: v} -> {k: v}
|
---|
16 | * @param {!Array.<string|number>} path The property path to flatten
|
---|
17 | * @param {!Object} obj The provided object
|
---|
18 | * @return {!Object} The flattened object
|
---|
19 | * @see {@link RA.flattenProp|flattenProp}, {@link RA.spreadPath|spreadPath}
|
---|
20 | * @example
|
---|
21 | *
|
---|
22 | * RA.flattenPath(
|
---|
23 | * ['b1', 'b2'],
|
---|
24 | * { a: 1, b1: { b2: { c: 3, d: 4 } } }
|
---|
25 | * ); // => { a: 1, c: 3, d: 4, b1: { b2: { c: 3, d: 4 } } };
|
---|
26 | */
|
---|
27 | var flattenPath = (0, _ramda.curry)(function (path, obj) {
|
---|
28 | return (0, _ramda.mergeRight)(obj, (0, _ramda.pathOr)({}, path, obj));
|
---|
29 | });
|
---|
30 | var _default = flattenPath;
|
---|
31 | exports["default"] = _default; |
---|