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.
33 lines
791 B
33 lines
791 B
1 month ago
|
import baseProperty from './_baseProperty.js';
|
||
|
import basePropertyDeep from './_basePropertyDeep.js';
|
||
|
import isKey from './_isKey.js';
|
||
|
import toKey from './_toKey.js';
|
||
|
|
||
|
/**
|
||
|
* Creates a function that returns the value at `path` of a given object.
|
||
|
*
|
||
|
* @static
|
||
|
* @memberOf _
|
||
|
* @since 2.4.0
|
||
|
* @category Util
|
||
|
* @param {Array|string} path The path of the property to get.
|
||
|
* @returns {Function} Returns the new accessor function.
|
||
|
* @example
|
||
|
*
|
||
|
* var objects = [
|
||
|
* { 'a': { 'b': 2 } },
|
||
|
* { 'a': { 'b': 1 } }
|
||
|
* ];
|
||
|
*
|
||
|
* _.map(objects, _.property('a.b'));
|
||
|
* // => [2, 1]
|
||
|
*
|
||
|
* _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
|
||
|
* // => [1, 2]
|
||
|
*/
|
||
|
function property(path) {
|
||
|
return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
|
||
|
}
|
||
|
|
||
|
export default property;
|