|
Last change
on this file since ba17441 was a762898, checked in by istevanoska <ilinastevanoska@…>, 6 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
827 bytes
|
| Line | |
|---|
| 1 | import { isKey } from '../_internal/isKey.mjs';
|
|---|
| 2 | import { toKey } from '../_internal/toKey.mjs';
|
|---|
| 3 | import { toPath } from '../util/toPath.mjs';
|
|---|
| 4 | import { toString } from '../util/toString.mjs';
|
|---|
| 5 |
|
|---|
| 6 | function result(object, path, defaultValue) {
|
|---|
| 7 | if (isKey(path, object)) {
|
|---|
| 8 | path = [path];
|
|---|
| 9 | }
|
|---|
| 10 | else if (!Array.isArray(path)) {
|
|---|
| 11 | path = toPath(toString(path));
|
|---|
| 12 | }
|
|---|
| 13 | const pathLength = Math.max(path.length, 1);
|
|---|
| 14 | for (let index = 0; index < pathLength; index++) {
|
|---|
| 15 | const value = object == null ? undefined : object[toKey(path[index])];
|
|---|
| 16 | if (value === undefined) {
|
|---|
| 17 | return typeof defaultValue === 'function' ? defaultValue.call(object) : defaultValue;
|
|---|
| 18 | }
|
|---|
| 19 | object = typeof value === 'function' ? value.call(object) : value;
|
|---|
| 20 | }
|
|---|
| 21 | return object;
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | export { result };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.