Skip to content

Commit

Permalink
refactor: update JSDoc annotations in image library
Browse files Browse the repository at this point in the history
  • Loading branch information
tooooo1 committed Sep 26, 2023
1 parent f17fd59 commit 49849e0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
3 changes: 1 addition & 2 deletions packages/image/src/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
21 changes: 9 additions & 12 deletions packages/image/src/extractRGBAs.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion packages/image/src/load.ts
Original file line number Diff line number Diff line change
@@ -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<HTMLImageElement>((resolve, reject) => {
Expand Down

0 comments on commit 49849e0

Please sign in to comment.