-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathindex.d.ts
More file actions
140 lines (128 loc) · 3.8 KB
/
index.d.ts
File metadata and controls
140 lines (128 loc) · 3.8 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
140
// Type definitions
import { IOptions as SanitizeOptions } from 'sanitize-html'
/**
* Transformation for per-site HTML pre/post processing.
*/
export interface Transformation {
/** URL regex patterns to match */
patterns: Array<RegExp>
/** Function to pre-process raw HTML before extraction */
pre?: (document: Document) => Document
/** Function to post-process extracted article content */
post?: (document: Document) => Document
}
/**
* Options for the article extraction process.
*/
export interface ParserOptions {
/** Words per minute for time-to-read estimation. Default: 300 */
wordsPerMinute?: number
/** Max chars for generated description. Default: 210 */
descriptionTruncateLen?: number
/** Min chars required for description. Default: 180 */
descriptionLengthThreshold?: number
/** Min chars required for content. Default: 200 */
contentLengthThreshold?: number
}
/**
* Proxy configuration for fetching articles.
*/
export interface ProxyConfig {
/** Proxy endpoint URL */
target?: string
/** Headers for proxy request */
headers?: Record<string, string>
}
/**
* Options for the HTTP fetch request.
*/
export interface FetchOptions {
/** Custom request headers */
headers?: Record<string, string>
/** Proxy configuration */
proxy?: ProxyConfig
/** HTTP proxy agent (e.g. HttpsProxyAgent) */
agent?: object
/** AbortSignal to cancel the request */
signal?: object
}
/**
* Extracted article data structure.
*/
export interface ArticleData {
/** Best resolved URL of the article */
url?: string
/** Alternative URLs (canonical, shortlink, etc.) */
links?: string[]
/** Article title */
title?: string
/** Short description or excerpt */
description?: string
/** Main image URL */
image?: string
/** Site favicon URL */
favicon?: string
/** Author name */
author?: string
/** Extracted article HTML content */
content?: string
/** Original publisher/source domain */
source?: string
/** Publication date string */
published?: string
/** Estimated time to read in seconds (0 = unknown) */
ttr?: number
/** Page type (e.g. article) */
type?: string
}
/**
* Register one or more transformations for per-site HTML processing.
*
* @param transformations - Single transformation or array of transformations
* @returns Number of transformations successfully added
*/
export function addTransformations (transformations: Transformation | Array<Transformation>): number
/**
* Remove transformations matching the given patterns.
* Calling without arguments removes all transformations.
*
* @param patterns - URL patterns to match for removal
* @returns Number of transformations removed
*/
export function removeTransformations (patterns?: Array<RegExp>): number
/**
* Get a copy of the current sanitize-html options.
*/
export function getSanitizeHtmlOptions (): SanitizeOptions
/**
* Update sanitize-html options by merging with the current ones.
*
* @param options - Partial sanitize options to merge
*/
export function setSanitizeHtmlOptions (options: SanitizeOptions): void
/**
* Load and extract article data from a URL or HTML string.
*
* @param input - URL or HTML string to extract from
* @param parserOptions - Options for parsing
* @param fetchOptions - Options for HTTP fetch
* @returns Extracted article data or null
*/
export function extract (
input: string,
parserOptions?: ParserOptions,
fetchOptions?: FetchOptions,
): Promise<ArticleData | null>
/**
* Extract article data from an HTML string directly.
*
* @param html - Raw HTML content
* @param url - Source URL for resolving relative links
* @param parserOptions - Options for parsing
* @returns Extracted article data or null
*/
export function extractFromHtml (
html: string,
url?: string,
parserOptions?: ParserOptions,
): Promise<ArticleData | null>