-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript support #8
Comments
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 |
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 considering to add this package to definitelytyped, but for teh mean time: This is the declaration I always usedeclare 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>
}
} |
If it doesn't require coding in TS, then you're free to add declaration file to project |
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?
The text was updated successfully, but these errors were encountered: