open-learning-exchange/planet

View on GitHub
chatapi/src/utils/text-extraction.utils.ts

Summary

Maintainability
A
0 mins
Test Coverage
import textract from 'textract';

export async function extractTextFromDocument(data: Buffer, mimetype: string): Promise<string> {
  return new Promise((resolve, reject) => {
    textract.fromBufferWithMime(mimetype, data, (error, text) => {
      if (error) {
        reject(error);
      } else {
        resolve(text);
      }
    });
  });
}