UNPKG

672 BJavaScriptView Raw
1var castPath = require('./_castPath'),
2 isKey = require('./_isKey'),
3 toKey = require('./_toKey');
4
5/**
6 * The base implementation of `_.get` without support for default values.
7 *
8 * @private
9 * @param {Object} object The object to query.
10 * @param {Array|string} path The path of the property to get.
11 * @returns {*} Returns the resolved value.
12 */
13function baseGet(object, path) {
14 path = isKey(path, object) ? [path] : castPath(path);
15
16 var index = 0,
17 length = path.length;
18
19 while (object != null && index < length) {
20 object = object[toKey(path[index++])];
21 }
22 return (index && index == length) ? object : undefined;
23}
24
25module.exports = baseGet;