source: node_modules/ramda-adjunct/lib/pathOrLazy.js@ 65b6638

main
Last change on this file since 65b6638 was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.2 KB
Line 
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5var _ramda = require("ramda");
6/**
7 * If the given, non-null object has a value at the given path, returns the value at that path.
8 * Otherwise returns the result of invoking the provided function with the object.
9 *
10 * @func pathOrLazy
11 * @memberOf RA
12 * @since {@link https://char0n.github.io/ramda-adjunct/2.22.0|v2.22.0}
13 * @category Object
14 * @typedef Idx = String | Int
15 * @sig ({a} -> a) -> [Idx] -> {a} -> a
16 * @param {Function} defaultFn The function that will return the default value.
17 * @param {Array} path The path to use.
18 * @param {Object} obj The object to retrieve the nested property from.
19 * @return {*} The data at `path` of the supplied object or the default value.
20 * @example
21 *
22 * RA.pathOrLazy(() => 'N/A', ['a', 'b'], {a: {b: 2}}); //=> 2
23 * RA.pathOrLazy(() => 'N/A', ['a', 'b'], {c: {b: 2}}); //=> "N/A"
24 */
25var pathOrLazy = (0, _ramda.curryN)(3, function (defaultFn, path, obj) {
26 return (0, _ramda.when)((0, _ramda.identical)(defaultFn), (0, _ramda.partial)((0, _ramda.unary)(defaultFn), [obj]), (0, _ramda.pathOr)(defaultFn, path, obj));
27});
28var _default = pathOrLazy;
29exports["default"] = _default;
Note: See TracBrowser for help on using the repository browser.