|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | import { isDeepKey } from '../_internal/isDeepKey.mjs';
|
|---|
| 2 | import { isIndex } from '../_internal/isIndex.mjs';
|
|---|
| 3 | import { isArguments } from '../predicate/isArguments.mjs';
|
|---|
| 4 | import { toPath } from '../util/toPath.mjs';
|
|---|
| 5 |
|
|---|
| 6 | function hasIn(object, path) {
|
|---|
| 7 | if (object == null) {
|
|---|
| 8 | return false;
|
|---|
| 9 | }
|
|---|
| 10 | let resolvedPath;
|
|---|
| 11 | if (Array.isArray(path)) {
|
|---|
| 12 | resolvedPath = path;
|
|---|
| 13 | }
|
|---|
| 14 | else if (typeof path === 'string' && isDeepKey(path) && object[path] == null) {
|
|---|
| 15 | resolvedPath = toPath(path);
|
|---|
| 16 | }
|
|---|
| 17 | else {
|
|---|
| 18 | resolvedPath = [path];
|
|---|
| 19 | }
|
|---|
| 20 | if (resolvedPath.length === 0) {
|
|---|
| 21 | return false;
|
|---|
| 22 | }
|
|---|
| 23 | let current = object;
|
|---|
| 24 | for (let i = 0; i < resolvedPath.length; i++) {
|
|---|
| 25 | const key = resolvedPath[i];
|
|---|
| 26 | if (current == null || !(key in Object(current))) {
|
|---|
| 27 | const isSparseIndex = (Array.isArray(current) || isArguments(current)) && isIndex(key) && key < current.length;
|
|---|
| 28 | if (!isSparseIndex) {
|
|---|
| 29 | return false;
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 | current = current[key];
|
|---|
| 33 | }
|
|---|
| 34 | return true;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | export { hasIn };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.