source: node_modules/es-toolkit/dist/compat/object/has.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.1 KB
RevLine 
[a762898]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 has(object, path) {
11 let resolvedPath;
12 if (Array.isArray(path)) {
13 resolvedPath = path;
14 }
15 else if (typeof path === 'string' && isDeepKey.isDeepKey(path) && object?.[path] == null) {
16 resolvedPath = toPath.toPath(path);
17 }
18 else {
19 resolvedPath = [path];
20 }
21 if (resolvedPath.length === 0) {
22 return false;
23 }
24 let current = object;
25 for (let i = 0; i < resolvedPath.length; i++) {
26 const key = resolvedPath[i];
27 if (current == null || !Object.hasOwn(current, key)) {
28 const isSparseIndex = (Array.isArray(current) || isArguments.isArguments(current)) && isIndex.isIndex(key) && key < current.length;
29 if (!isSparseIndex) {
30 return false;
31 }
32 }
33 current = current[key];
34 }
35 return true;
36}
37
38exports.has = has;
Note: See TracBrowser for help on using the repository browser.