Skip to content

Commit 05bf44b

Browse files
authored
🤖 Merge PR DefinitelyTyped#74384 [colorthief] Add static method declaration for Node.js usage by @na-trium-144
1 parent 4c2dfea commit 05bf44b

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

‎types/colorthief/colorthief-tests.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
// Import the ColorThief class for testing
55
import ColorThief from "colorthief";
66

7+
// Node.js version tests
8+
const imgPath = "rainbow.png";
9+
10+
// Test getColor method
11+
const dominantColorNode: Promise<ColorThief.RGBColor> = ColorThief.getColor(imgPath);
12+
const dominantColorWithQualityNode: Promise<ColorThief.RGBColor> = ColorThief.getColor(imgPath, 5);
13+
14+
// Test getPalette method
15+
const paletteNode: Promise<ColorThief.RGBColor[]> = ColorThief.getPalette(imgPath);
16+
const paletteWithOptionsNode: Promise<ColorThief.RGBColor[]> = ColorThief.getPalette(imgPath, 8, 5);
17+
718
// Browser version tests
819
const colorThief = new ColorThief();
920
const img = document.createElement("img");

‎types/colorthief/index.d.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/// <reference lib="dom" />
2+
/// <reference types="node" />
23

34
export = ColorThief;
45
export as namespace ColorThief;
@@ -41,6 +42,38 @@ declare namespace ColorThief {
4142
* Color Thief - Extract dominant colors from images
4243
*/
4344
declare class ColorThief {
45+
// --------------------------------------------------------
46+
// Node.js usage (Static methods returning Promises)
47+
// --------------------------------------------------------
48+
49+
/**
50+
* Extract the dominant color from an image (Node.js)
51+
* @param sourceImage - Path to the image file, or Buffer containing image
52+
* @param quality - Quality/speed trade-off (1 = highest quality, 10 = default)
53+
* @returns Promise resolving to RGB color array [r, g, b] where values are 0-255
54+
*/
55+
static getColor(
56+
sourceImage: Buffer | Uint8Array | ArrayBuffer | string,
57+
quality?: number,
58+
): Promise<ColorThief.RGBColor>;
59+
60+
/**
61+
* Extract a palette of colors from an image (Node.js)
62+
* @param sourceImage - Path to the image file, or Buffer containing image
63+
* @param colorCount - Number of colors to extract (2-20, default: 10)
64+
* @param quality - Quality/speed trade-off (1 = highest quality, 10 = default)
65+
* @returns Promise resolving to Array of RGB color arrays [[r, g, b], ...] where values are 0-255
66+
*/
67+
static getPalette(
68+
sourceImage: Buffer | Uint8Array | ArrayBuffer | string,
69+
colorCount?: number,
70+
quality?: number,
71+
): Promise<ColorThief.RGBColor[]>;
72+
73+
// --------------------------------------------------------
74+
// Browser usage (Instance methods)
75+
// --------------------------------------------------------
76+
4477
/**
4578
* Extract the dominant color from an image
4679
* @param sourceImage - HTML image element

‎types/colorthief/package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"projects": [
66
"https://github.com/lokesh/color-thief"
77
],
8+
"dependencies": {
9+
"@types/node": "*"
10+
},
811
"devDependencies": {
912
"@types/colorthief": "workspace:."
1013
},

0 commit comments

Comments
 (0)