Closed sglkc closed 5 months ago
i don't want this project to be in ts
i respect your preference
I'm wondering why this isn't included as a default? Puppeteer has full TS integration, why not include the types for this? Not trying to be pedantic, I'm genuinely interested.
I don't like TS and having to build the project
I don't like TS and having to build the project
You don't have to actually build the project, just a single declaration file, add types field in package.json, and since types are used in imports, private methods can be ignored.
I'm wondering why this isn't included as a default? Puppeteer has full TS integration, why not include the types for this? Not trying to be pedantic, I'm genuinely interested.
I'm considering to add this package to definitelytyped, but for teh mean time:
If it doesn't require coding in TS, then you're free to add declaration file to project
I don't like TS and having to build the project
You don't have to actually build the project, just a single declaration file, add types field in package.json, and since types are used in imports, private methods can be ignored.
I'm wondering why this isn't included as a default? Puppeteer has full TS integration, why not include the types for this? Not trying to be pedantic, I'm genuinely interested.
I'm considering to add this package to definitelytyped, but for teh mean time:
This is the declaration I always use
declare module 'chrome-lens-ocr' { import type { IncomingHttpHeaders } from 'node:http' export const LENS_ENDPOINT = 'https://lens.google.com/v3/upload' export const LENS_API_ENDPOINT = 'https://lens.google.com/uploadbyurl' export const SUPPORTED_MIMES = [ 'image/x-icon', 'image/bmp', 'image/jpeg', 'image/png', 'image/tiff', 'image/webp', 'image/heic', ] as const export const MIME_TO_EXT: Record<typeof SUPPORTED_MIMES[number], string> = { 'image/x-icon': 'ico', 'image/bmp': 'bmp', 'image/jpeg': 'jpg', 'image/png': 'png', 'image/tiff': 'tiff', 'image/webp': 'webp', 'image/heic': 'heic' }; export type LensOptions = { chromeVersion: string majorChromeVersion: string userAgent: string endpoint: string viewport: [number, number] headers: IncomingHttpHeaders | Headers fetchOptions: RequestInit } export class BoundingBox { centerPerX: number // center of the bounding box on X axis, in % of the image width centerPerY: number // center of the bounding box on Y axis, in % of the image height perWidth: number // width of the bounding box, in % of the image width perHeight: number // height of the bounding box, in % of the image height pixelCoords: { x: number // top-left corner X coordinate, in pixels y: number // top-left corner Y coordinate, in pixels width: number, // width of the bounding box, in pixels height: number, // height of the bounding box, in pixels } } export class Segment { text: string boundingBox: BoundingBox } export class LensResult { language: string segments: Segment[] } export class LensError extends Error { name: 'LensError' message: string code: string headers: Headers body: string } export class LensCore { cookies: NavigatorCookies constructor(options?: Partial<LensOptions>, _fetchFunction?: typeof fetch) updateOptions(options: Partial<LensOptions>): void scanByURL(url: string | URL, dimensions?: [number, number] = [0, 0]): Promise<LensResult> scanByData( data: Uint8Array, mime: SUPPORTED_MIMES, originalDimensions: [number, number] ): Promise<LensResult> static getAFData(text: string): object static parseResult( afData: object, imageDimensions: [number, number] ): LensResult } export default class Lens extends LensCore { constructor(options?: Partial<LensOptions>, _fetchFunction?: typeof fetch) scanByFile(path: string): Promise<LensResult> scanByBuffer(buffer: Buffer): Promise<LensResult> } }
That looks quite ok, why not include it in the build? People that (for whatever reason) don't like TS, can still just use the JS build
Currently you have to depend on README to know the APIs, by adding types you can help save time in development. It should be easy since everything is already documented though. Should I make a PR?