/**
 * Gets the value at path of object.
 * If the resolved value is undefined, the defaultValue is returned in its place.
 */
export function getObjectValue(object, path, value) {
  if (!path) {
    return value;
  }
  const pathArray = Array.isArray(path)
    ? path
    : path.split(".").filter(key => key);
  const pathArrayFlat = pathArray.flatMap(part =>
    typeof part === "string" ? part.split(".") : part,
  );

  return pathArrayFlat.reduce((obj, key) => obj && obj[key], object) || value;
}
