Skip to content

Commit 9b2b6d2

Browse files
committed
Adding Comments
1 parent 530de7a commit 9b2b6d2

File tree

5 files changed

+132
-7
lines changed

5 files changed

+132
-7
lines changed

netlify/edge-functions/analyze-image.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ import {
88

99
await initialize();
1010

11+
/**
12+
* Handles the image analysis request.
13+
*
14+
* @param request - The incoming HTTP request.
15+
* @returns The HTTP response with brightness and histogram data or an error message.
16+
* @throws Will throw an error if the request method is not POST or if processing fails.
17+
*
18+
* @example
19+
* // How to call the function.
20+
* fetch('/api/analyze-image', { method: 'POST', body: formData });
21+
*/
1122
export default async (request: Request) => {
1223
if (request.method === "POST") {
1324
try {

netlify/edge-functions/convert-image.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ import {
88

99
await initialize();
1010

11+
/**
12+
* Handles the image conversion request.
13+
*
14+
* @param request - The incoming HTTP request.
15+
* @returns The HTTP response with the converted image or an error message.
16+
* @throws Will throw an error if the request method is not POST or if processing fails.
17+
*
18+
* @example
19+
* // How to call the function.
20+
* fetch('/api/convert-image', { method: 'POST', body: formData });
21+
*/
1122
export default async (request: Request) => {
1223
if (request.method === "POST") {
1324
try {
@@ -66,18 +77,22 @@ export default async (request: Request) => {
6677
return new Response("Method Not Allowed", { status: 405 });
6778
};
6879

69-
function capitalizeWords(str) {
70-
// Split the string into an array of words
80+
/**
81+
* Capitalizes the first letter of each word in a string.
82+
*
83+
* @param str - The string to capitalize.
84+
* @returns The capitalized string.
85+
*
86+
* @example
87+
* // How to use the function.
88+
* const capitalized = capitalizeWords("example string");
89+
*/
90+
function capitalizeWords(str: string): string {
7191
const words = str.split(" ");
72-
73-
// Loop through each word and capitalize the first letter
7492
const capitalizedWords = words.map((word) => {
7593
return word.charAt(0).toUpperCase() + word.slice(1);
7694
});
77-
78-
// Join the capitalized words back into a string
7995
const capitalizedString = capitalizedWords.join(" ");
80-
8196
return capitalizedString;
8297
}
8398

netlify/edge-functions/edge-enhance.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ import {
1010

1111
await initialize();
1212

13+
/**
14+
* Handles the image edge enhancement request.
15+
*
16+
* @param request - The incoming HTTP request.
17+
* @returns The HTTP response with the enhanced image or an error message.
18+
* @throws Will throw an error if the request method is not POST or if processing fails.
19+
*
20+
* @example
21+
* // How to call the function.
22+
* fetch('/api/edge-enhance', { method: 'POST', body: formData });
23+
*/
1324
export default async (request: Request) => {
1425
if (request.method === "POST") {
1526
try {

netlify/edge-functions/image-dimensions.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import { multiParser } from "https://deno.land/x/multiparser@0.114.0/mod.ts";
22

3+
/**
4+
* Handles the image dimensions request.
5+
*
6+
* @param request - The incoming HTTP request.
7+
* @returns The HTTP response with the image dimensions or an error message.
8+
* @throws Will throw an error if the request method is not POST or if processing fails.
9+
*
10+
* @example
11+
* // How to call the function.
12+
* fetch('/api/image-dimensions', { method: 'POST', body: formData });
13+
*/
314
export default async (request: Request) => {
415
if (request.method === "POST") {
516
try {
@@ -63,6 +74,17 @@ export default async (request: Request) => {
6374
return new Response("Method Not Allowed", { status: 405 });
6475
};
6576

77+
/**
78+
* Extracts the dimensions of a JPEG image.
79+
*
80+
* @param data - The image data as a Uint8Array.
81+
* @returns The width and height of the image.
82+
* @throws Will throw an error if the JPEG file is invalid or dimensions are not found.
83+
*
84+
* @example
85+
* // How to use the function.
86+
* const dimensions = getJpegDimensions(fileData);
87+
*/
6688
function getJpegDimensions(data: Uint8Array): {
6789
width: number;
6890
height: number;
@@ -94,6 +116,17 @@ function getJpegDimensions(data: Uint8Array): {
94116
throw new Error("No size information found in JPEG");
95117
}
96118

119+
/**
120+
* Extracts the dimensions of a PNG image.
121+
*
122+
* @param data - The image data as a Uint8Array.
123+
* @returns The width and height of the image.
124+
* @throws Will throw an error if the PNG file is invalid.
125+
*
126+
* @example
127+
* // How to use the function.
128+
* const dimensions = getPngDimensions(fileData);
129+
*/
97130
function getPngDimensions(data: Uint8Array): { width: number; height: number } {
98131
if (
99132
data[0] !== 0x89 ||
@@ -109,6 +142,17 @@ function getPngDimensions(data: Uint8Array): { width: number; height: number } {
109142
return { width, height };
110143
}
111144

145+
/**
146+
* Extracts the dimensions of a GIF image.
147+
*
148+
* @param data - The image data as a Uint8Array.
149+
* @returns The width and height of the image.
150+
* @throws Will throw an error if the GIF file is invalid.
151+
*
152+
* @example
153+
* // How to use the function.
154+
* const dimensions = getGifDimensions(fileData);
155+
*/
112156
function getGifDimensions(data: Uint8Array): { width: number; height: number } {
113157
if (data[0] !== 0x47 || data[1] !== 0x49 || data[2] !== 0x46) {
114158
throw new Error("Invalid GIF file");
@@ -119,13 +163,35 @@ function getGifDimensions(data: Uint8Array): { width: number; height: number } {
119163
return { width, height };
120164
}
121165

166+
/**
167+
* Extracts the dimensions of a BMP image.
168+
*
169+
* @param data - The image data as a Uint8Array.
170+
* @returns The width and height of the image.
171+
* @throws Will throw an error if the BMP file is invalid.
172+
*
173+
* @example
174+
* // How to use the function.
175+
* const dimensions = getBmpDimensions(fileData);
176+
*/
122177
function getBmpDimensions(data: Uint8Array): { width: number; height: number } {
123178
const view = new DataView(data.buffer);
124179
const width = view.getInt32(18, true); // Little endian
125180
const height = view.getInt32(22, true); // Little endian
126181
return { width, height };
127182
}
128183

184+
/**
185+
* Extracts the dimensions of a TIFF image.
186+
*
187+
* @param data - The image data as a Uint8Array.
188+
* @returns The width and height of the image.
189+
* @throws Will throw an error if the TIFF file is invalid or dimensions are not found.
190+
*
191+
* @example
192+
* // How to use the function.
193+
* const dimensions = getTiffDimensions(fileData);
194+
*/
129195
function getTiffDimensions(data: Uint8Array): {
130196
width: number;
131197
height: number;
@@ -173,6 +239,17 @@ function getTiffDimensions(data: Uint8Array): {
173239
return { width, height };
174240
}
175241

242+
/**
243+
* Extracts the dimensions of an SVG image.
244+
*
245+
* @param data - The image data as a Uint8Array.
246+
* @returns The width and height of the image.
247+
* @throws Will throw an error if the SVG file is invalid.
248+
*
249+
* @example
250+
* // How to use the function.
251+
* const dimensions = getSvgDimensions(fileData);
252+
*/
176253
function getSvgDimensions(data: Uint8Array): { width: number; height: number } {
177254
const decoder = new TextDecoder("utf-8");
178255
const svgContent = decoder.decode(data);

netlify/edge-functions/resize-image.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ import {
99

1010
await initialize();
1111

12+
/**
13+
* Handles the image resize request.
14+
*
15+
* @param request - The incoming HTTP request.
16+
* @returns The HTTP response with the resized image or an error message.
17+
* @throws Will throw an error if the request method is not POST or if processing fails.
18+
*
19+
* @example
20+
* // How to call the function.
21+
* fetch('/api/resize-image', { method: 'POST', body: formData });
22+
*/
1223
export default async (request: Request) => {
1324
if (request.method === "POST") {
1425
try {

0 commit comments

Comments
 (0)