MultiLoader-Template/node_modules/es-toolkit/dist/compat/object/result.mjs
3944Realms 768f38fc97 feat: 可使用的构建模板
修改了脚本,使其可以推给Maven仓库
2026-05-03 13:02:19 +08:00

25 lines
827 B
JavaScript

import { isKey } from '../_internal/isKey.mjs';
import { toKey } from '../_internal/toKey.mjs';
import { toPath } from '../util/toPath.mjs';
import { toString } from '../util/toString.mjs';
function result(object, path, defaultValue) {
if (isKey(path, object)) {
path = [path];
}
else if (!Array.isArray(path)) {
path = toPath(toString(path));
}
const pathLength = Math.max(path.length, 1);
for (let index = 0; index < pathLength; index++) {
const value = object == null ? undefined : object[toKey(path[index])];
if (value === undefined) {
return typeof defaultValue === 'function' ? defaultValue.call(object) : defaultValue;
}
object = typeof value === 'function' ? value.call(object) : value;
}
return object;
}
export { result };