Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

870 B
Raw Blame
// Client-side classification entry point: extract the PDF, then classify it.

import i18n from "i18next";
import { classifyHeuristic } from "@editor/services/heuristic/heuristicEngine";
import {
  extractHeuristicDoc,
  type ExtractOptions,
} from "@editor/services/heuristic/heuristicExtractor";
import type { HeuristicResult } from "@editor/services/heuristic/types";

/** Classify a file in the browser. Throws if extraction fails: unreadable, non-PDF, or a
 *  `budgetMs` that runs out before any text is read. */
export async function classifyFileHeuristically(
  file: File,
  opts?: { explain?: boolean } & ExtractOptions,
): Promise<HeuristicResult> {
  const doc = await extractHeuristicDoc(file, file.name, {
    budgetMs: opts?.budgetMs,
  });
  return classifyHeuristic(doc, {
    explain: opts?.explain,
    localeHint: i18n.language ?? undefined,
  });
}