-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
propOr.js
36 lines (34 loc) · 1.05 KB
/
propOr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import _curry3 from './internal/_curry3.js';
import defaultTo from './defaultTo.js';
import prop from './prop.js';
/**
* Return the specified property of the given non-null object if the property
* is present and it's value is not `null`, `undefined` or `NaN`.
*
* Otherwise the first argument is returned.
*
* @func
* @memberOf R
* @since v0.6.0
* @category Object
* @sig a -> String -> Object -> a
* @param {*} val The default value.
* @param {String} p The name of the property to return.
* @param {Object} obj The object to query.
* @return {*} The value of given property of the supplied object or the default value.
* @example
*
* const alice = {
* name: 'ALICE',
* age: 101
* };
* const favorite = R.prop('favoriteLibrary');
* const favoriteWithDefault = R.propOr('Ramda', 'favoriteLibrary');
*
* favorite(alice); //=> undefined
* favoriteWithDefault(alice); //=> 'Ramda'
*/
var propOr = _curry3(function propOr(val, p, obj) {
return defaultTo(val, prop(p, obj));
});
export default propOr;