export function downloadBlob(blob: Blob, fileName: string) {
  const url = URL.createObjectURL(blob)
  const anchor = document.createElement("a")
  anchor.href = url
  anchor.download = fileName
  anchor.click()
  URL.revokeObjectURL(url)
}

function baseNameWithoutExt(fileName: string): string {
  const slash = fileName.lastIndexOf("/")
  const base = slash >= 0 ? fileName.slice(slash + 1) : fileName
  const dot = base.lastIndexOf(".")
  return dot > 0 ? base.slice(0, dot) : base
}

export function exportFileName(sourceName: string, ext: string): string {
  return `${baseNameWithoutExt(sourceName)}.${ext}`
}

export function baseNameFromSource(sourceName: string): string {
  return baseNameWithoutExt(sourceName)
}
