@wordpress/core-data
Version:
Access to and manipulation of core WordPress entities.
17 lines (16 loc) • 538 B
JavaScript
// packages/core-data/src/utils/get-nested-value.js
function getNestedValue(object, path, defaultValue) {
if (!object || typeof object !== "object" || typeof path !== "string" && !Array.isArray(path)) {
return object;
}
const normalizedPath = Array.isArray(path) ? path : path.split(".");
let value = object;
normalizedPath.forEach((fieldName) => {
value = value?.[fieldName];
});
return value !== void 0 ? value : defaultValue;
}
export {
getNestedValue as default
};
//# sourceMappingURL=get-nested-value.js.map