mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
755 B
31 lines
755 B
9 years ago
|
var baseProperty = require('./_baseProperty'),
|
||
|
basePropertyDeep = require('./_basePropertyDeep'),
|
||
|
isKey = require('./_isKey');
|
||
10 years ago
|
|
||
|
/**
|
||
9 years ago
|
* Creates a function that returns the value at `path` of a given object.
|
||
10 years ago
|
*
|
||
|
* @static
|
||
|
* @memberOf _
|
||
9 years ago
|
* @category Util
|
||
10 years ago
|
* @param {Array|string} path The path of the property to get.
|
||
|
* @returns {Function} Returns the new function.
|
||
|
* @example
|
||
|
*
|
||
|
* var objects = [
|
||
|
* { 'a': { 'b': { 'c': 2 } } },
|
||
|
* { 'a': { 'b': { 'c': 1 } } }
|
||
|
* ];
|
||
|
*
|
||
|
* _.map(objects, _.property('a.b.c'));
|
||
|
* // => [2, 1]
|
||
|
*
|
||
9 years ago
|
* _.map(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
|
||
10 years ago
|
* // => [1, 2]
|
||
|
*/
|
||
|
function property(path) {
|
||
|
return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
|
||
|
}
|
||
|
|
||
|
module.exports = property;
|