import { NativeModules, Platform } from 'react-native'; import { Match } from '../../utils'; import type { Patterns, PDFExtractor, TextResult } from '../../types'; const PdfExtractor = Platform.select({ android: NativeModules.PdfExtractor, ios: {}, }) as PDFExtractor; export class BaseExtractor { static async getUri(): Promise { return PdfExtractor.getUri(); } static async isEncrypted(): Promise { return PdfExtractor.isEncrypted(); } static async setUri(uri: string): Promise { return PdfExtractor.setUri(uri); } static async getNumberOfPages(password?: string): Promise { return PdfExtractor.getNumberOfPages(password); } static async canIExtract(): Promise { return PdfExtractor.canIExtract(); } static async getText(password?: string): Promise { const data = await PdfExtractor.getText(password); return [...new Set(data?.split('\n') || [])] as string[]; } static async getTextWithPattern( pattern: Patterns, password?: string ): Promise { const patterns = Array.isArray(pattern) ? pattern : [pattern]; const data = await this.getText(password); const matches = patterns.map((regex) => Match(regex, data)); return [...new Set(matches)].flat(); } }