Skip to content

Commit f122634

Browse files
committed
Add docs
1 parent ea4d419 commit f122634

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

src/index.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import md5 from "md5";
22
import qs from "qs";
33

4+
/**
5+
* The type of capture request to perform.
6+
*/
47
export type RequestType = "image" | "pdf" | "content" | "metadata" | "animated";
8+
9+
/**
10+
* Options that can be passed to customize the capture request.
11+
*/
512
export type RequestOptions = Record<string, string | number | boolean>;
613

14+
/**
15+
* Main class for interacting with the Capture.page API.
16+
*/
717
export class Capture {
818
static API_URL = "https://cdn.capture.page";
919
static EDGE_URL = "https://edge.capture.page";
@@ -12,6 +22,13 @@ export class Capture {
1222
secret: string;
1323
options: { useEdge?: boolean };
1424

25+
/**
26+
* Creates a new Capture instance.
27+
*
28+
* @param key - Your Capture.page API key
29+
* @param secret - Your Capture.page API secret
30+
* @param options - Optional configuration
31+
*/
1532
constructor(key: string, secret: string, options?: { useEdge?: boolean }) {
1633
this.key = key;
1734
this.secret = secret;
@@ -80,26 +97,68 @@ export class Capture {
8097
return `${this.options.useEdge ? Capture.EDGE_URL : Capture.API_URL}/${this.key}/${token}/${type}?${query}`;
8198
}
8299

100+
/**
101+
* Builds a URL for capturing a screenshot image.
102+
*
103+
* @param url - The target URL to capture
104+
* @param options - Optional request parameters to customize the capture
105+
* @returns The complete API URL for the image capture request
106+
*/
83107
buildImageUrl(url: string, options?: RequestOptions): string {
84108
return this._buildUrl("image", url, options);
85109
}
86110

111+
/**
112+
* Builds a URL for capturing a PDF.
113+
*
114+
* @param url - The target URL to capture
115+
* @param options - Optional request parameters to customize the capture
116+
* @returns The complete API URL for the PDF capture request
117+
*/
87118
buildPdfUrl(url: string, options?: RequestOptions): string {
88119
return this._buildUrl("pdf", url, options);
89120
}
90121

122+
/**
123+
* Builds a URL for capturing page content (HTML and text).
124+
*
125+
* @param url - The target URL to capture
126+
* @param options - Optional request parameters to customize the capture
127+
* @returns The complete API URL for the content capture request
128+
*/
91129
buildContentUrl(url: string, options?: RequestOptions): string {
92130
return this._buildUrl("content", url, options);
93131
}
94132

133+
/**
134+
* Builds a URL for capturing page metadata.
135+
*
136+
* @param url - The target URL to capture
137+
* @param options - Optional request parameters to customize the capture
138+
* @returns The complete API URL for the metadata capture request
139+
*/
95140
buildMetadataUrl(url: string, options?: RequestOptions): string {
96141
return this._buildUrl("metadata", url, options);
97142
}
98143

144+
/**
145+
* Builds a URL for capturing an animated screenshot (GIF or video).
146+
*
147+
* @param url - The target URL to capture
148+
* @param options - Optional request parameters to customize the capture
149+
* @returns The complete API URL for the animated capture request
150+
*/
99151
buildAnimatedUrl(url: string, options?: RequestOptions): string {
100152
return this._buildUrl("animated", url, options);
101153
}
102154

155+
/**
156+
* Captures and fetches a screenshot image.
157+
*
158+
* @param url - The target URL to capture
159+
* @param options - Optional request parameters to customize the capture
160+
* @returns A promise that resolves to the image data as an ArrayBuffer
161+
*/
103162
async fetchImage(
104163
url: string,
105164
options?: RequestOptions,
@@ -109,19 +168,40 @@ export class Capture {
109168
);
110169
}
111170

171+
/**
172+
* Captures and fetches a PDF.
173+
*
174+
* @param url - The target URL to capture
175+
* @param options - Optional request parameters to customize the capture
176+
* @returns A promise that resolves to the PDF data as an ArrayBuffer
177+
*/
112178
async fetchPdf(url: string, options?: RequestOptions): Promise<ArrayBuffer> {
113179
return fetch(this.buildPdfUrl(url, options)).then((res) =>
114180
res.arrayBuffer(),
115181
);
116182
}
117183

184+
/**
185+
* Captures and fetches page content (HTML and text).
186+
*
187+
* @param url - The target URL to capture
188+
* @param options - Optional request parameters to customize the capture
189+
* @returns A promise that resolves to an object containing the HTML and text content
190+
*/
118191
async fetchContent(
119192
url: string,
120193
options?: RequestOptions,
121194
): Promise<{ success: boolean; html: string; textContent: string }> {
122195
return fetch(this.buildContentUrl(url, options)).then((res) => res.json());
123196
}
124197

198+
/**
199+
* Captures and fetches page metadata.
200+
*
201+
* @param url - The target URL to capture
202+
* @param options - Optional request parameters to customize the capture
203+
* @returns A promise that resolves to an object containing the page metadata
204+
*/
125205
async fetchMetadata(
126206
url: string,
127207
options?: RequestOptions,
@@ -132,6 +212,13 @@ export class Capture {
132212
return fetch(this.buildMetadataUrl(url, options)).then((res) => res.json());
133213
}
134214

215+
/**
216+
* Captures and fetches an animated screenshot (GIF or video).
217+
*
218+
* @param url - The target URL to capture
219+
* @param options - Optional request parameters to customize the capture
220+
* @returns A promise that resolves to the animated content as an ArrayBuffer
221+
*/
135222
async fetchAnimated(
136223
url: string,
137224
options?: RequestOptions,

0 commit comments

Comments
 (0)