Skip to content

Commit 0db6c23

Browse files
committed
fix: remove unused dependency 'grab-url' and refactor grab function
1 parent c5a52f5 commit 0db6c23

3 files changed

Lines changed: 30 additions & 6 deletions

File tree

packages/extract-pdf/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
"test": "bun test",
2626
"ship": "npm run build && npx standard-version --release-as patch; rm -f CHANGELOG.md; npm publish"
2727
},
28-
"dependencies": {
29-
"grab-url": "^1.6.19"
30-
},
28+
"dependencies": {},
3129
"devDependencies": {
3230
"terser": "^5.46.0",
3331
"typescript": "^5.9.3",

packages/extract-pdf/src/pdf-to-html.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
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-
75
import {
86
findPageNumbers,
97
findFirstPage,
@@ -12,6 +10,34 @@ import {
1210
import TextItem from "./models/text-item";
1311
import 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+
1541
import CalculateGlobalStats from "./transforms/calculate-global-stats";
1642
import CompactLines from "./transforms/line-item/compact-lines";
1743
import RemoveRepetitiveElements from "./transforms/line-item/remove-repetitive-elements";

packages/extract-pdf/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default defineConfig({
1717
format: { comments: false },
1818
},
1919
rollupOptions: {
20-
external: ["grab-url"],
20+
external: [],
2121
},
2222
},
2323
plugins: [

0 commit comments

Comments
 (0)