source: node_modules/ramda/es/propOr.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.1 KB
Line 
1import _curry3 from "./internal/_curry3.js";
2import defaultTo from "./defaultTo.js";
3import prop from "./prop.js";
4/**
5 * Return the specified property of the given non-null object if the property
6 * is present and it's value is not `null`, `undefined` or `NaN`.
7 *
8 * Otherwise the first argument is returned.
9 *
10 * @func
11 * @memberOf R
12 * @since v0.6.0
13 * @category Object
14 * @sig a -> String -> Object -> a
15 * @param {*} val The default value.
16 * @param {String} p The name of the property to return.
17 * @param {Object} obj The object to query.
18 * @return {*} The value of given property of the supplied object or the default value.
19 * @example
20 *
21 * const alice = {
22 * name: 'ALICE',
23 * age: 101
24 * };
25 * const favorite = R.prop('favoriteLibrary');
26 * const favoriteWithDefault = R.propOr('Ramda', 'favoriteLibrary');
27 *
28 * favorite(alice); //=> undefined
29 * favoriteWithDefault(alice); //=> 'Ramda'
30 */
31
32var propOr =
33/*#__PURE__*/
34_curry3(function propOr(val, p, obj) {
35 return defaultTo(val, prop(p, obj));
36});
37
38export default propOr;
Note: See TracBrowser for help on using the repository browser.