gev2002 / react-native-vision-camera-v3-text-recognition

https://www.npmjs.com/package/react-native-vision-camera-v3-text-recognition
MIT License
19 stars 6 forks source link

fix: return types; callback prop types #6

Closed pedrol2b closed 6 months ago

pedrol2b commented 6 months ago

[!NOTE] Merge #4 and #5 in one. Sorry for the mess

Adds types for the result/return of scanText Replaces the current return type of the function with TextDataMap interface

before

const data: object = scanText(frame, options);

after

export type TextData = {
  blockFrameBottom: number
  blockFrameLeft: number
  blockFrameRight: number
  blockFrameTop: number
  blockText: string
  elementFrameBottom: number
  elementFrameLeft: number
  elementFrameRight: number
  elementFrameTop: number
  elementText: string
  lineFrameBottom: number
  lineFrameLeft: number
  lineFrameRight: number
  lineFrameTop: number
  lineText: string
  resultText: string
  size: number
}

export type TextDataMap = {
  [key: number]: TextData
}
const data = scanText(frame, options);

Adds TextDataMap in callback

export type CameraTypes = {
  callback: (data: TextDataMap) => void;
  options: TextRecognitionOptions;
} & CameraProps;

usage

       callback={(data) => {
            const map: Map<string, typeof data> = new Map(Object.entries(data))
            const result = map.get('0')
            console.log(result)
          }}