lokesh / color-thief

Grab the color palette from an image using just Javascript. Works in the browser and in Node.

Home Page:https://lokeshdhakar.com/projects/color-thief/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

typescript declaration file

nblthree opened this issue · comments

Try npm install @types/colorthief if it exists or add a new declaration (.d.ts) file containing declare module 'colorthief';

unfortunately it doesn't exist

Here's a colorthief.d.ts that works for me. I put it in src/types and typescript picked it up automatically.

declare module 'colorthief' {
  type Color = [number, number, number];
  export default class ColorThief {
    getColor: (img: HTMLImageElement | null) => Color;
    getPalette: (img: HTMLImageElement | null) => Color[];
  }
}
commented

version with optional parameters:

declare module 'colorthief' {
    export type RGBColor = [number, number, number];
    export default class ColorThief {
        getColor: (img: HTMLImageElement | null, quality: number=10) => RGBColor;
        getPalette: (img: HTMLImageElement | null, colorCount: number=10, quality: number=10) => RGBColor[];
    }
}