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.
40 lines
1.1 KiB
40 lines
1.1 KiB
var baseCastPath = require('./_baseCastPath'),
|
|
isArguments = require('./isArguments'),
|
|
isArray = require('./isArray'),
|
|
isIndex = require('./_isIndex'),
|
|
isKey = require('./_isKey'),
|
|
isLength = require('./isLength'),
|
|
isString = require('./isString');
|
|
|
|
/**
|
|
* 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) {
|
|
path = isKey(path, object) ? [path] : baseCastPath(path);
|
|
|
|
var result,
|
|
index = -1,
|
|
length = path.length;
|
|
|
|
while (++index < length) {
|
|
var key = path[index];
|
|
if (!(result = object != null && hasFunc(object, key))) {
|
|
break;
|
|
}
|
|
object = object[key];
|
|
}
|
|
if (result) {
|
|
return result;
|
|
}
|
|
var length = object ? object.length : 0;
|
|
return !!length && isLength(length) && isIndex(key, length) &&
|
|
(isArray(object) || isString(object) || isArguments(object));
|
|
}
|
|
|
|
module.exports = hasPath;
|
|
|