1 | "use strict";
|
---|
2 |
|
---|
3 | exports.__esModule = true;
|
---|
4 | exports["default"] = void 0;
|
---|
5 | var _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 | */
|
---|
25 | var 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 | });
|
---|
28 | var _default = pathOrLazy;
|
---|
29 | exports["default"] = _default; |
---|