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 | |
---|
1 | import _curry3 from "./internal/_curry3.js";
|
---|
2 | import defaultTo from "./defaultTo.js";
|
---|
3 | import 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 |
|
---|
32 | var propOr =
|
---|
33 | /*#__PURE__*/
|
---|
34 | _curry3(function propOr(val, p, obj) {
|
---|
35 | return defaultTo(val, prop(p, obj));
|
---|
36 | });
|
---|
37 |
|
---|
38 | export default propOr; |
---|
Note:
See
TracBrowser
for help on using the repository browser.