export function isPlainObject(
  value: unknown,
): value is Record<PropertyKey, unknown> {
  if (value === null || typeof value !== `object`) return false
  const prototype = Object.getPrototypeOf(value)
  return prototype === Object.prototype || prototype === null
}

/**
 * Type guard to check if a value is promise-like (has a `.then` method)
 * @param value - The value to check
 * @returns True if the value is promise-like, false otherwise
 */
export function isPromiseLike(value: unknown): value is PromiseLike<unknown> {
  return (
    !!value &&
    (typeof value === `object` || typeof value === `function`) &&
    typeof (value as { then?: unknown }).then === `function`
  )
}
