Last change
on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
793 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | var baseProperty = require('./_baseProperty'),
|
---|
| 2 | basePropertyDeep = require('./_basePropertyDeep'),
|
---|
| 3 | isKey = require('./_isKey'),
|
---|
| 4 | toKey = require('./_toKey');
|
---|
| 5 |
|
---|
| 6 | /**
|
---|
| 7 | * Creates a function that returns the value at `path` of a given object.
|
---|
| 8 | *
|
---|
| 9 | * @static
|
---|
| 10 | * @memberOf _
|
---|
| 11 | * @since 2.4.0
|
---|
| 12 | * @category Util
|
---|
| 13 | * @param {Array|string} path The path of the property to get.
|
---|
| 14 | * @returns {Function} Returns the new accessor function.
|
---|
| 15 | * @example
|
---|
| 16 | *
|
---|
| 17 | * var objects = [
|
---|
| 18 | * { 'a': { 'b': 2 } },
|
---|
| 19 | * { 'a': { 'b': 1 } }
|
---|
| 20 | * ];
|
---|
| 21 | *
|
---|
| 22 | * _.map(objects, _.property('a.b'));
|
---|
| 23 | * // => [2, 1]
|
---|
| 24 | *
|
---|
| 25 | * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
|
---|
| 26 | * // => [1, 2]
|
---|
| 27 | */
|
---|
| 28 | function property(path) {
|
---|
| 29 | return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | module.exports = property;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.