2016-11-14 20:54:18 -08:00
|
|
|
define(['./_castPath', './isArguments', './isArray', './_isIndex', './isLength', './_toKey'], function(castPath, isArguments, isArray, isIndex, isLength, toKey) {
|
2016-01-28 01:16:24 -08:00
|
|
|
|
2015-12-16 17:53:20 -08:00
|
|
|
/**
|
|
|
|
|
* Checks if `path` exists on `object`.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Object} object The object to query.
|
|
|
|
|
* @param {Array|string} path The path to check.
|
|
|
|
|
* @param {Function} hasFunc The function to check properties.
|
|
|
|
|
* @returns {boolean} Returns `true` if `path` exists, else `false`.
|
|
|
|
|
*/
|
|
|
|
|
function hasPath(object, path, hasFunc) {
|
2016-11-14 20:54:18 -08:00
|
|
|
path = castPath(path, object);
|
2016-03-26 00:00:01 -07:00
|
|
|
|
2016-09-17 22:24:52 -07:00
|
|
|
var index = -1,
|
|
|
|
|
length = path.length,
|
|
|
|
|
result = false;
|
2016-03-26 00:00:01 -07:00
|
|
|
|
2016-04-01 23:28:48 -07:00
|
|
|
while (++index < length) {
|
2016-04-19 22:17:16 -07:00
|
|
|
var key = toKey(path[index]);
|
2016-04-01 23:28:48 -07:00
|
|
|
if (!(result = object != null && hasFunc(object, key))) {
|
|
|
|
|
break;
|
2015-12-16 17:53:20 -08:00
|
|
|
}
|
2016-04-01 23:28:48 -07:00
|
|
|
object = object[key];
|
|
|
|
|
}
|
2016-09-17 22:24:52 -07:00
|
|
|
if (result || ++index != length) {
|
2016-04-01 23:28:48 -07:00
|
|
|
return result;
|
2015-12-16 17:53:20 -08:00
|
|
|
}
|
2016-10-30 20:06:57 -07:00
|
|
|
length = object == null ? 0 : object.length;
|
2016-04-01 23:28:48 -07:00
|
|
|
return !!length && isLength(length) && isIndex(key, length) &&
|
2016-08-11 23:27:31 -07:00
|
|
|
(isArray(object) || isArguments(object));
|
2015-12-16 17:53:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hasPath;
|
|
|
|
|
});
|