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