mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 01:47:48 +00:00
Bump to v4.0.0.
This commit is contained in:
30
internal/hasPath.js
Normal file
30
internal/hasPath.js
Normal file
@@ -0,0 +1,30 @@
|
||||
define(['./baseToPath', '../isArguments', '../isArray', './isIndex', './isKey', '../isLength', '../isString', '../last', './parent'], function(baseToPath, isArguments, isArray, isIndex, isKey, isLength, isString, last, parent) {
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if (object == null) {
|
||||
return false;
|
||||
}
|
||||
var result = hasFunc(object, path);
|
||||
if (!result && !isKey(path)) {
|
||||
path = baseToPath(path);
|
||||
object = parent(object, path);
|
||||
if (object != null) {
|
||||
path = last(path);
|
||||
result = hasFunc(object, path);
|
||||
}
|
||||
}
|
||||
return result || (isLength(object && object.length) && isIndex(path, object.length) &&
|
||||
(isArray(object) || isString(object) || isArguments(object)));
|
||||
}
|
||||
|
||||
return hasPath;
|
||||
});
|
||||
Reference in New Issue
Block a user