1 | var castPath = require('./_castPath'),
|
2 | isArguments = require('./isArguments'),
|
3 | isArray = require('./isArray'),
|
4 | isIndex = require('./_isIndex'),
|
5 | isLength = require('./isLength'),
|
6 | toKey = require('./_toKey');
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | function hasPath(object, path, hasFunc) {
|
18 | path = castPath(path, object);
|
19 |
|
20 | var index = -1,
|
21 | length = path.length,
|
22 | result = false;
|
23 |
|
24 | while (++index < length) {
|
25 | var key = toKey(path[index]);
|
26 | if (!(result = object != null && hasFunc(object, key))) {
|
27 | break;
|
28 | }
|
29 | object = object[key];
|
30 | }
|
31 | if (result || ++index != length) {
|
32 | return result;
|
33 | }
|
34 | length = object == null ? 0 : object.length;
|
35 | return !!length && isLength(length) && isIndex(key, length) &&
|
36 | (isArray(object) || isArguments(object));
|
37 | }
|
38 |
|
39 | module.exports = hasPath;
|