22 * @fileoverview High-fidelity PDF-to-HTML conversion pipeline.
33 * Extracts structural elements (headers, lists, code blocks) and handles page-level metadata.
44 */
5- import { grab } from "grab-url" ;
6-
75import {
86 findPageNumbers ,
97 findFirstPage ,
@@ -12,6 +10,34 @@ import {
1210import TextItem from "./models/text-item" ;
1311import Page from "./models/page" ;
1412
13+ /**
14+ * Fetch wrapper for grabbing binary content
15+ */
16+ async function grab ( url : string , options : { responseType ?: string ; timeout ?: number } = { } ) {
17+ const timeout = options . timeout ? options . timeout * 1000 : 10000 ;
18+ const controller = new AbortController ( ) ;
19+ const timeoutId = setTimeout ( ( ) => controller . abort ( ) , timeout ) ;
20+
21+ try {
22+ const response = await fetch ( url , {
23+ signal : controller . signal ,
24+ } ) ;
25+ clearTimeout ( timeoutId ) ;
26+
27+ if ( ! response . ok ) {
28+ throw new Error ( `HTTP ${ response . status } ` ) ;
29+ }
30+
31+ if ( options . responseType === "arraybuffer" ) {
32+ return await response . arrayBuffer ( ) ;
33+ }
34+ return await response . text ( ) ;
35+ } catch ( error ) {
36+ clearTimeout ( timeoutId ) ;
37+ throw error ;
38+ }
39+ }
40+
1541import CalculateGlobalStats from "./transforms/calculate-global-stats" ;
1642import CompactLines from "./transforms/line-item/compact-lines" ;
1743import RemoveRepetitiveElements from "./transforms/line-item/remove-repetitive-elements" ;
0 commit comments