c063592ce9a5fc02050b26ab06d579ddf90cf878
[yaffs-website] / node_modules / grunt-legacy-util / node_modules / lodash / _hasPath.js
1 var baseToPath = require('./_baseToPath'),
2     isArguments = require('./isArguments'),
3     isArray = require('./isArray'),
4     isIndex = require('./_isIndex'),
5     isKey = require('./_isKey'),
6     isLength = require('./isLength'),
7     isString = require('./isString'),
8     last = require('./last'),
9     parent = require('./_parent');
10
11 /**
12  * Checks if `path` exists on `object`.
13  *
14  * @private
15  * @param {Object} object The object to query.
16  * @param {Array|string} path The path to check.
17  * @param {Function} hasFunc The function to check properties.
18  * @returns {boolean} Returns `true` if `path` exists, else `false`.
19  */
20 function hasPath(object, path, hasFunc) {
21   if (object == null) {
22     return false;
23   }
24   var result = hasFunc(object, path);
25   if (!result && !isKey(path)) {
26     path = baseToPath(path);
27     object = parent(object, path);
28     if (object != null) {
29       path = last(path);
30       result = hasFunc(object, path);
31     }
32   }
33   var length = object ? object.length : undefined;
34   return result || (
35     !!length && isLength(length) && isIndex(path, length) &&
36     (isArray(object) || isString(object) || isArguments(object))
37   );
38 }
39
40 module.exports = hasPath;