any-extractor 1.0.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -6
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ A Node.js package to extract text from any file.
|
|
|
16
16
|
- [Getting Started](#getting-started)
|
|
17
17
|
- [Advanced Usage](#advanced-usage)
|
|
18
18
|
- [Custom Parsers](#custom-parsers)
|
|
19
|
+
- [Confluence Crawling](#confluence-crawling)
|
|
19
20
|
- [Needs Work](#needs-work)
|
|
20
21
|
- [Contributing](#contributing)
|
|
21
22
|
- [Credits](#credits)
|
|
@@ -26,11 +27,12 @@ A Node.js package to extract text from any file.
|
|
|
26
27
|
|
|
27
28
|
- **Multi-format file support:** Extracts text from a wide range of file types. (See below for list of supported files)
|
|
28
29
|
- **OCR for images:** Uses Optical Character Recognition to extract text from images within documents and standalone image files.
|
|
29
|
-
- **LLM for image description:** Leverages AI to extract
|
|
30
|
+
- **LLM for image description:** Leverages AI to extract images description, providing richer information.
|
|
30
31
|
- **ES6 and CommonJS support:** Supports both modern ES6 and traditional CommonJS JavaScript environments.
|
|
31
32
|
- **Flexible input options:** Supports local file path, buffers, and file URLs.
|
|
32
33
|
- **Auto type detection:** Automatically detects file type and extracts text using MIME type.
|
|
33
34
|
- **Customizable parsers:** Allows creating new or modifying existing document parsers for any MIME types.
|
|
35
|
+
- **Confluence support:** Extracts text from Confluence documents.
|
|
34
36
|
|
|
35
37
|
#### Supported Files
|
|
36
38
|
|
|
@@ -52,6 +54,7 @@ Here's a breakdown of the text extraction capabilities for each file type:
|
|
|
52
54
|
| `.txt` | ✅ | N/A |
|
|
53
55
|
| `.json` | ✅ | N/A |
|
|
54
56
|
| Plain text (e.g., `.py`,<br> `.ts`, `.md`, etc.) | ✅ | N/A |
|
|
57
|
+
| `confluence` | ✅ | ✅ |
|
|
55
58
|
|
|
56
59
|
## Installation
|
|
57
60
|
|
|
@@ -77,7 +80,7 @@ import { getAnyExtractor } from 'any-extractor';
|
|
|
77
80
|
|
|
78
81
|
async function extractFromFile() {
|
|
79
82
|
const anyExt = getAnyExtractor();
|
|
80
|
-
const text = await anyExt.
|
|
83
|
+
const text = await anyExt.parseFile('./filename.docx');
|
|
81
84
|
console.log('Extracted Text:', text);
|
|
82
85
|
}
|
|
83
86
|
|
|
@@ -91,7 +94,7 @@ const { getAnyExtractor } = require('any-extractor');
|
|
|
91
94
|
|
|
92
95
|
async function extractFromFile() {
|
|
93
96
|
const textExt = getAnyExtractor();
|
|
94
|
-
const result = await textExt.
|
|
97
|
+
const result = await textExt.parseFile('./filename.docx');
|
|
95
98
|
console.log(result);
|
|
96
99
|
}
|
|
97
100
|
|
|
@@ -109,7 +112,7 @@ AnyExtractor provides two primary methods for extracting text from images.
|
|
|
109
112
|
```ts
|
|
110
113
|
const anyExt = getAnyExtractor();
|
|
111
114
|
|
|
112
|
-
const text = await anyExt.
|
|
115
|
+
const text = await anyExt.parseFile('./imgfile.png', null, {
|
|
113
116
|
extractImages: true,
|
|
114
117
|
imageExtractionMethod: 'ocr',
|
|
115
118
|
language: 'eng',
|
|
@@ -127,7 +130,7 @@ AnyExtractor provides two primary methods for extracting text from images.
|
|
|
127
130
|
apikey: '<your-api-key>',
|
|
128
131
|
});
|
|
129
132
|
|
|
130
|
-
const text = await anyExt.
|
|
133
|
+
const text = await anyExt.parseFile('./imgfile.png', null, {
|
|
131
134
|
extractImages: true,
|
|
132
135
|
imageExtractionMethod: 'llm',
|
|
133
136
|
language: 'eng',
|
|
@@ -138,10 +141,22 @@ AnyExtractor provides two primary methods for extracting text from images.
|
|
|
138
141
|
|
|
139
142
|
> Llm parsing supports `openai`, `google` and `anthropic` llmProvider for now. But you can always overwrite the image parser implementation with your code.
|
|
140
143
|
|
|
141
|
-
> Optional argument of `getAnyExtractor` and `
|
|
144
|
+
> Optional argument of methods `getAnyExtractor` and `parseFile` are required for the extractor to parse images. Otherwise it will return empty string.
|
|
142
145
|
|
|
143
146
|
> Image parsing also works other files, e.g., .docx, .pptx etc (see the table above).
|
|
144
147
|
|
|
148
|
+
#### Authorization Parameter
|
|
149
|
+
|
|
150
|
+
The second argument in `parseFile`, shown as `null`, is for Basic Authentication when accessing file URLs. Format: `Basic <base64-encoded-credentials>`
|
|
151
|
+
|
|
152
|
+
Example:
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
const authString = 'Basic ' + Buffer.from('user:password').toString('base64');
|
|
156
|
+
const text = await anyExt.parseFile('https://example.com/protected-file.docx', authString);
|
|
157
|
+
console.log('Extracted Text:', text);
|
|
158
|
+
```
|
|
159
|
+
|
|
145
160
|
#### Custom Parsers:
|
|
146
161
|
|
|
147
162
|
AnyExtractor is designed with extensibility in mind, allowing you to integrate your own custom document parsers for handling specific or less common file formats, or to implement tailored text extraction logic.<br>
|
|
@@ -184,6 +199,38 @@ console.log('Extracted Text:', text);
|
|
|
184
199
|
|
|
185
200
|
> Creating custom parsers for existing mimetypes will overwrite the implementation.
|
|
186
201
|
|
|
202
|
+
#### Confluence Crawling
|
|
203
|
+
|
|
204
|
+
Extract text from Confluence documents:
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
const { getAnyExtractor } = require('any-extractor');
|
|
208
|
+
|
|
209
|
+
async function crawlConfluence() {
|
|
210
|
+
const textExt = getAnyExtractor({
|
|
211
|
+
llm: {
|
|
212
|
+
llmProvider: 'google',
|
|
213
|
+
visionModel: 'gemini-2.0-flash',
|
|
214
|
+
apikey: '<your-api-key>',
|
|
215
|
+
},
|
|
216
|
+
confluence: {
|
|
217
|
+
baseUrl: '<baseurl>',
|
|
218
|
+
email: '<username>',
|
|
219
|
+
apiKey: '<api-key>',
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
const result = await textExt.parseConfluenceDoc('<pageId>', {
|
|
224
|
+
extractAttachments: true,
|
|
225
|
+
extractImages: false,
|
|
226
|
+
imageExtractionMethod: 'ocr',
|
|
227
|
+
language: 'eng',
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
crawlConfluence();
|
|
232
|
+
```
|
|
233
|
+
|
|
187
234
|
## Needs Work
|
|
188
235
|
|
|
189
236
|
1. `.pdf` and `OpenOffice` files doesn't support image extraction.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "any-extractor",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A universal text extractor for files.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -85,6 +85,7 @@
|
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
87
|
"@xmldom/xmldom": "^0.9.8",
|
|
88
|
+
"cheerio": "^1.0.0",
|
|
88
89
|
"concat-stream": "^2.0.0",
|
|
89
90
|
"file-type-mime": "^0.4.6",
|
|
90
91
|
"js-yaml": "^4.1.0",
|