source: node_modules/es-toolkit/dist/compat/object/hasIn.js

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.2 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const isDeepKey = require('../_internal/isDeepKey.js');
6const isIndex = require('../_internal/isIndex.js');
7const isArguments = require('../predicate/isArguments.js');
8const toPath = require('../util/toPath.js');
9
10function hasIn(object, path) {
11 if (object == null) {
12 return false;
13 }
14 let resolvedPath;
15 if (Array.isArray(path)) {
16 resolvedPath = path;
17 }
18 else if (typeof path === 'string' && isDeepKey.isDeepKey(path) && object[path] == null) {
19 resolvedPath = toPath.toPath(path);
20 }
21 else {
22 resolvedPath = [path];
23 }
24 if (resolvedPath.length === 0) {
25 return false;
26 }
27 let current = object;
28 for (let i = 0; i < resolvedPath.length; i++) {
29 const key = resolvedPath[i];
30 if (current == null || !(key in Object(current))) {
31 const isSparseIndex = (Array.isArray(current) || isArguments.isArguments(current)) && isIndex.isIndex(key) && key < current.length;
32 if (!isSparseIndex) {
33 return false;
34 }
35 }
36 current = current[key];
37 }
38 return true;
39}
40
41exports.hasIn = hasIn;
Note: See TracBrowser for help on using the repository browser.