pwlmaciejewski / imghash

Perceptual image hashing for Node.js
MIT License
167 stars 19 forks source link

TypeScript support #133

Open Eghizio opened 3 years ago

Eghizio commented 3 years ago

Any plans for the TypeScript support?

Eghizio commented 3 years ago

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 commented 3 years ago

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

pwlmaciejewski commented 3 years ago

@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.

Eghizio commented 3 years ago

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