vuestic-ui
Version:
Vue 3 UI Framework
43 lines (42 loc) • 1.06 kB
JavaScript
import { i as isObject } from "./is-object.js";
import { i as isNilValue } from "./isNilValue.js";
const getNestedValue = (option, propsArray) => {
if (propsArray.length === 0) {
return option;
}
const nestedItem = option[propsArray[0]];
if (!isObject(nestedItem)) {
if (propsArray.length === 1) {
return nestedItem;
}
return void 0;
}
return getNestedValue(nestedItem, propsArray.slice(1));
};
const getValueByPath = (option, prop) => {
if (prop in option) {
return option[prop];
}
prop = prop.replace(/^\./, "");
return getNestedValue(option, prop.split("."));
};
const getValueByKey = (option, prop) => {
if (isNilValue(option) || typeof option !== "object" || Array.isArray(option)) {
return void 0;
}
if (!prop) {
return option;
}
if (typeof prop === "string") {
return getValueByPath(option, prop);
}
if (typeof prop === "function") {
return prop(option);
}
return option;
};
export {
getValueByKey as a,
getValueByPath as g
};
//# sourceMappingURL=value-by-key.js.map