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:
992 bytes
|
Line | |
---|
1 | var _curry2 =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./internal/_curry2.js");
|
---|
4 |
|
---|
5 | var _isInteger =
|
---|
6 | /*#__PURE__*/
|
---|
7 | require("./internal/_isInteger.js");
|
---|
8 |
|
---|
9 | var nth =
|
---|
10 | /*#__PURE__*/
|
---|
11 | require("./nth.js");
|
---|
12 | /**
|
---|
13 | * Returns a function that when supplied an object returns the indicated
|
---|
14 | * property of that object, if it exists.
|
---|
15 | *
|
---|
16 | * @func
|
---|
17 | * @memberOf R
|
---|
18 | * @since v0.1.0
|
---|
19 | * @category Object
|
---|
20 | * @typedefn Idx = String | Int | Symbol
|
---|
21 | * @sig Idx -> {s: a} -> a | Undefined
|
---|
22 | * @param {String|Number} p The property name or array index
|
---|
23 | * @param {Object} obj The object to query
|
---|
24 | * @return {*} The value at `obj.p`.
|
---|
25 | * @see R.path, R.props, R.pluck, R.project, R.nth
|
---|
26 | * @example
|
---|
27 | *
|
---|
28 | * R.prop('x', {x: 100}); //=> 100
|
---|
29 | * R.prop('x', {}); //=> undefined
|
---|
30 | * R.prop(0, [100]); //=> 100
|
---|
31 | * R.compose(R.inc, R.prop('x'))({ x: 3 }) //=> 4
|
---|
32 | */
|
---|
33 |
|
---|
34 |
|
---|
35 | var prop =
|
---|
36 | /*#__PURE__*/
|
---|
37 | _curry2(function prop(p, obj) {
|
---|
38 | if (obj == null) {
|
---|
39 | return;
|
---|
40 | }
|
---|
41 |
|
---|
42 | return _isInteger(p) ? nth(p, obj) : obj[p];
|
---|
43 | });
|
---|
44 |
|
---|
45 | module.exports = prop; |
---|
Note:
See
TracBrowser
for help on using the repository browser.