imghash icon indicating copy to clipboard operation
imghash copied to clipboard

TypeScript support

Open Eghizio opened this issue 3 years ago • 4 comments

Any plans for the TypeScript support?

Eghizio avatar Jul 02 '21 22:07 Eghizio

I've quickly mocked something like this:

// index.d.ts
/// <reference types="node" />


// fs filepath: PathLike | number;
// type PathLike = string | Buffer | URL;
type Filepath = string | Buffer;

type Format = "hex" | "binary";

// blockhash ImageData
type Data = {
    width: number;
    height: number;
    data: Uint8Array | Uint8ClampedArray | number[];
};

export declare function hash(filepath: Filepath, bits?: number, format?: Format): Promise<string>;
export declare function hashRaw(data: Data, bits: number): string;
export declare function hexToBinary(s: string): string;
export declare function binaryToHex(s: string): string;

I've also noticed that the lookup has mixed string | number keys:

https://github.com/pwlmaciejewski/imghash/blob/master/index.js#L100 Is that intended? image

Eghizio avatar Jul 02 '21 22:07 Eghizio

Tbh it is infering nicely most of the stuff from the dependencies, tho no direct typings therefore TS complains about lack of them.

Eghizio avatar Jul 02 '21 22:07 Eghizio

@Eghizio Thank you 🙏

Is that intended?

I think that's prettier's doing 😬 Is this causing any trouble?

no direct typings therefore TS complains about lack of them.

Can you push a PR? I would love to rewrite the whole thing to TS but for now the manual typing should do.

pwlmaciejewski avatar Sep 09 '21 10:09 pwlmaciejewski

No problem. No it is not causing any problems. I'll try to do it as soon as I can ;)

Eghizio avatar Sep 10 '21 00:09 Eghizio