import { get } from './get.mjs';

function internalSet(entity, paths, value, removeIfUndefined) {
  if (!paths.length)
    return value;
  const [path, ...restPath] = paths;
  let clone;
  if (!entity && typeof path === "number")
    clone = [];
  else if (Array.isArray(entity))
    clone = [...entity];
  else
    clone = { ...entity };
  if (removeIfUndefined && value === void 0 && restPath.length === 1)
    delete clone[path][restPath[0]];
  else
    clone[path] = internalSet(clone[path], restPath, value, removeIfUndefined);
  return clone;
}
function set(entity, paths, value, removeIfUndefined = false) {
  if (paths.length && removeIfUndefined && value === void 0 && !get(entity, paths.slice(0, -1)))
    return entity;
  return internalSet(entity, paths, value, removeIfUndefined);
}

export { set };
//# sourceMappingURL=set.mjs.map
