Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(image): JSDoc Annotations Update #54

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/red-llamas-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fepack/image": patch
---

refactor(image): JSDoc Annotations Update
2 changes: 2 additions & 0 deletions packages/image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"fepack",
"image"
],
"homepage": "https://image.fepack.org",
"repository": {
"type": "git",
"url": "https://github.com/fepack/image.git",
Expand All @@ -32,6 +33,7 @@
"./package.json": "./package.json"
},
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist",
Expand Down
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