lokesh / color-thief

Grab the color palette from an image using just Javascript. Works in the browser and in Node.
https://lokeshdhakar.com/projects/color-thief/
MIT License
12.49k stars 1.31k forks source link

Inconsistent colorthief imports leads to crash in tests #248

Open tbragaf opened 1 year ago

tbragaf commented 1 year ago

I'm creating my own function which internally uses the GetPalette function. When using it in development mode, I can make it work simply by:

import Colorthief from "colorthief";

function getPaletteFromImage(img: HTMLImageElement, colorsCount: number, quality: number): string[] {
    const colorthief = new Colorthief();
    var palette = colorthief.getPalette(img, colorsCount, quality);

    // ... 
}

However, this fails when running tests stating the Colorthief is not defined .

I noticed that you export the ColorThief function as a default in https://github.com/lokesh/color-thief/blob/master/src/color-thief.js#L147. You then use it by creating an object in https://github.com/lokesh/color-thief/blob/master/examples/js/demo.js#L1.

But in your tests, you don't create any object, and simply use a function. https://github.com/lokesh/color-thief/blob/master/test/node-test.js#L17

Why is that?

Thank you, Tiago