From 49849e06a5cea31c74f845be46242e453f1a996e Mon Sep 17 00:00:00 2001 From: Chung-il Jung Date: Tue, 26 Sep 2023 17:12:59 +0900 Subject: [PATCH] refactor: update JSDoc annotations in image library --- packages/image/src/detect.ts | 3 +-- packages/image/src/extractRGBAs.ts | 21 +++++++++------------ packages/image/src/load.ts | 5 ++++- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/packages/image/src/detect.ts b/packages/image/src/detect.ts index 289acc5..d9accb6 100644 --- a/packages/image/src/detect.ts +++ b/packages/image/src/detect.ts @@ -40,8 +40,7 @@ const FILE_TYPE_KEYS = Object.keys( /** * Inspects the first few bytes of a buffer to determine if * it matches a known file signature. - * - * @param {Buffer} buffer - The buffer containing the file's first few bytes. + * @param buffer - The buffer containing the file's first few bytes. * @returns The detected MIME type or null if no known signature is matched. */ export const detect = (buffer: Buffer) => { diff --git a/packages/image/src/extractRGBAs.ts b/packages/image/src/extractRGBAs.ts index eea0608..b1d6ca2 100644 --- a/packages/image/src/extractRGBAs.ts +++ b/packages/image/src/extractRGBAs.ts @@ -1,17 +1,16 @@ type RGBA = readonly [number, number, number, number]; type ExtractRGBAsOptions = { quality: number }; const initialOptions: ExtractRGBAsOptions = { quality: 100 }; + /** * Filters and extracts relevant pixels from image data based on quality setting. + * @param image - The image data. + * @param [options] - The options to define the quality of extraction. + * @throws Will throw an error if quality is not between 1 and 100. + * @returns An array of RGBA values. */ export const extractRGBAs = ( - /** - * The image pixel data. - */ image: HTMLImageElement, - /** - * Quality setting for filtering pixels. Higher values mean more pixels are processed. Range: [1, 100] - */ options = initialOptions, ) => { if (options.quality < 1 || options.quality > 100) { @@ -36,13 +35,11 @@ export const extractRGBAs = ( /** * Extracts pixel data from an image. + * @param image - The image element. + * @throws Will throw an error if canvasRenderingContext2D is not supported. + * @returns The pixel data of the image. */ -const extractUint8ClampedArray = ( - /** - * The image element - */ - image: HTMLImageElement, -) => { +const extractUint8ClampedArray = (image: HTMLImageElement) => { const canvas = document.createElement("canvas"); const canvasRenderingContext2D = canvas.getContext("2d"); if (!canvasRenderingContext2D) { diff --git a/packages/image/src/load.ts b/packages/image/src/load.ts index babcab9..78b7676 100644 --- a/packages/image/src/load.ts +++ b/packages/image/src/load.ts @@ -1,5 +1,8 @@ /** - * Loads an image from the given source URL and returns a Promise that resolves to the loaded image. + * Loads an image from the given source URL. + * @param src - The source URL of the image to load. + * @returns A Promise that resolves to the loaded image. + * @throws Will reject the promise if the image fails to load. */ export const load = (src: HTMLImageElement["src"]) => new Promise((resolve, reject) => {