source: node_modules/ramda-adjunct/lib/flattenPath.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: 1.0 KB
RevLine 
[d24f17c]1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5var _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 */
27var flattenPath = (0, _ramda.curry)(function (path, obj) {
28 return (0, _ramda.mergeRight)(obj, (0, _ramda.pathOr)({}, path, obj));
29});
30var _default = flattenPath;
31exports["default"] = _default;
Note: See TracBrowser for help on using the repository browser.