source: node_modules/es-toolkit/dist/compat/object/result.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: 950 bytes
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const isKey = require('../_internal/isKey.js');
6const toKey = require('../_internal/toKey.js');
7const toPath = require('../util/toPath.js');
8const toString = require('../util/toString.js');
9
10function result(object, path, defaultValue) {
11 if (isKey.isKey(path, object)) {
12 path = [path];
13 }
14 else if (!Array.isArray(path)) {
15 path = toPath.toPath(toString.toString(path));
16 }
17 const pathLength = Math.max(path.length, 1);
18 for (let index = 0; index < pathLength; index++) {
19 const value = object == null ? undefined : object[toKey.toKey(path[index])];
20 if (value === undefined) {
21 return typeof defaultValue === 'function' ? defaultValue.call(object) : defaultValue;
22 }
23 object = typeof value === 'function' ? value.call(object) : value;
24 }
25 return object;
26}
27
28exports.result = result;
Note: See TracBrowser for help on using the repository browser.