Repository navigation
Expand file tree
/
Copy pathindex.d.ts
More file actions
139 lines (123 loc) · 3.79 KB
/
Copy pathindex.d.ts
File metadata and controls
139 lines (123 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import type { CheerioAPI } from 'cheerio'
/**
* Result returned by html-get
*/
export interface HtmlGetResult {
/** The HTML content */
html: string
/** Response headers */
headers: Record<string, string | string[] | undefined>
/** Final URL after redirects */
url: string
/** HTTP status code */
statusCode: number
/** Redirect history */
redirects: Array<{ statusCode: number; url: string }>
/** Mode used: 'fetch' or 'prerender' */
mode: 'fetch' | 'prerender'
/** Parsed HTML (Cheerio) */
$?: CheerioAPI
/** Statistics about the request */
stats: {
mode: 'fetch' | 'prerender'
timing: number
}
}
/**
* Options for html-get
*/
export interface HtmlGetOptions {
/** Character encoding for HTML (default: 'utf-8') */
encoding?: string
/** Function that returns a browserless instance (required unless prerender is false) */
getBrowserless?: () => Promise<any>
/** Function to determine the mode ('fetch' or 'prerender') */
getMode?: (url: string, options: { prerender: boolean | 'auto' }) => 'fetch' | 'prerender'
/** Function to create temporary files */
getTemporalFile?: (input: string, ext?: string) => { path: string }
/** Options passed to got (the HTTP client) */
gotOpts?: Record<string, any>
/** Request headers */
headers?: Record<string, string>
/** Mutool function for PDF processing, or false to disable */
mutool?: ((...args: string[]) => any) | false
/** Prerender mode: true, false, or 'auto' (default) */
prerender?: boolean | 'auto'
/** Options passed to Puppeteer */
puppeteerOpts?: Record<string, any>
/** Rewrite relative URLs to absolute */
rewriteUrls?: boolean
/** Rewrite common HTML meta tag mistakes */
rewriteHtml?: boolean
/** Function to serialize HTML (default: $ => ({ html: $.html() })) */
serializeHtml?: ($: CheerioAPI) => { html: string }
}
/**
* Main function to get HTML from a URL
*/
export function htmlGet(
targetUrl: string,
options?: HtmlGetOptions
): Promise<HtmlGetResult>
/**
* Check if a URL should use 'fetch' mode (no prerender needed)
*/
export function isFetchMode(url: string): boolean
/**
* Get content directly with a specific mode
*/
export function getContent(
url: string,
mode: 'fetch' | 'prerender',
options?: HtmlGetOptions
): Promise<HtmlGetResult>
/**
* Default mutool function (returns undefined if mutool is not installed)
*/
export function defaultMutool(): ((...args: string[]) => any) | undefined
/**
* Default request timeout in milliseconds
*/
export const REQ_TIMEOUT: number
/**
* Default abort types for prerendering
*/
export const ABORT_TYPES: string[]
/**
* PDF size threshold in bytes (150KB)
*/
export const PDF_SIZE_TRESHOLD: number
export interface PdfMeta {
title?: string | null
author?: string | null
authors?: string | null
description?: string | null
publisher?: string | null
date?: string | null
lang?: string | null
image?: string | null
logo?: string | null
}
/** Read title, author, date, and the rest from PDF bytes. */
export function extractPdf(input: {
url: string
pdf: ArrayBuffer | ArrayBufferView
maxPages?: number
}): Promise<PdfMeta>
/** `extractPdf` that returns undefined on a non-PDF or a parse error. */
export function extractPdfSafe(
input: ArrayBuffer | ArrayBufferView,
url: string,
opts?: { maxPages?: number }
): Promise<PdfMeta | undefined>
/** `true` when the bytes start with `%PDF` (junk before the header is allowed). */
export function isPdf(input: ArrayBuffer | ArrayBufferView): boolean
/** `true` when `url` looks like a PDF link. */
export function isPdfLink(url?: string): boolean
/** Empty HTML document with PDF metadata stamped as meta tags. */
export function pdfToHtml(
input: ArrayBuffer | ArrayBufferView,
url: string,
opts?: { maxPages?: number }
): Promise<string>
export default htmlGet