main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[d565449] | 1 | import castPath from './_castPath.js';
|
---|
| 2 | import isArguments from './isArguments.js';
|
---|
| 3 | import isArray from './isArray.js';
|
---|
| 4 | import isIndex from './_isIndex.js';
|
---|
| 5 | import isLength from './isLength.js';
|
---|
| 6 | import toKey from './_toKey.js';
|
---|
| 7 |
|
---|
| 8 | /**
|
---|
| 9 | * Checks if `path` exists on `object`.
|
---|
| 10 | *
|
---|
| 11 | * @private
|
---|
| 12 | * @param {Object} object The object to query.
|
---|
| 13 | * @param {Array|string} path The path to check.
|
---|
| 14 | * @param {Function} hasFunc The function to check properties.
|
---|
| 15 | * @returns {boolean} Returns `true` if `path` exists, else `false`.
|
---|
| 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 | export default hasPath;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.