Use word-extractor in typescript
popiero opened this issue · 1 comments
Good afternoon,
I'd like extract text from buffer of doc and docx file.
But I don't know as import the library into my ts file.
I used
import * as WORDEXTRACTOR from 'word-extractor';
and implemented this code:
WORDEXTRACTOR.fromBuffer(originalFile).then((doc: any) => {
// eslint-disable-next-line no-console
console.log(doc.getBody());
});
But in compile time I have an error :
Error ole....
Can You help me, please ?
I hope that this library is ok for my goal.
Thanks, everybody.
Hmmm, not sure I am qualified to comment on TypeScript, because I haven't really switched over to using it yet. However, there's no types here, so I will hazard as guess that it is the same as modern JavaScript import
usage.
So I tested this, and, if I create a file, test.mjs
as follows:
import WORDEXTRACTOR from 'word-extractor';
const extractor = new WORDEXTRACTOR();
Then it can run...
node --experimental-modules test.mjs
However, modifying it to:
import * as WORDEXTRACTOR from 'word-extractor';
const extractor = new WORDEXTRACTOR();
does not. As far as I can tell, this applies to all modules, and is basically what import *
is supposed to do, i.e., slurp in all the exports, named and otherwise, into a single object. The constructor would then be available as new WORDEXTRACTOR.default()
.
The best way around it is to use:
import WORDEXTRACTOR from 'word-extractor';
For now, I am assuming this is to do with import *
, not the module, and therefore closing. Please feel free to comment if this is not correct or as you expect.