doc-reader-sdk 0.0.0-stage → 1.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.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +220 -2
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +158 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/extractors/csv.d.ts +6 -0
  8. package/dist/extractors/csv.d.ts.map +1 -0
  9. package/dist/extractors/csv.js +62 -0
  10. package/dist/extractors/csv.js.map +1 -0
  11. package/dist/extractors/docx.d.ts +6 -0
  12. package/dist/extractors/docx.d.ts.map +1 -0
  13. package/dist/extractors/docx.js +58 -0
  14. package/dist/extractors/docx.js.map +1 -0
  15. package/dist/extractors/json.d.ts +10 -0
  16. package/dist/extractors/json.d.ts.map +1 -0
  17. package/dist/extractors/json.js +89 -0
  18. package/dist/extractors/json.js.map +1 -0
  19. package/dist/extractors/pdf.d.ts +6 -0
  20. package/dist/extractors/pdf.d.ts.map +1 -0
  21. package/dist/extractors/pdf.js +74 -0
  22. package/dist/extractors/pdf.js.map +1 -0
  23. package/dist/extractors/pptx.d.ts +6 -0
  24. package/dist/extractors/pptx.d.ts.map +1 -0
  25. package/dist/extractors/pptx.js +81 -0
  26. package/dist/extractors/pptx.js.map +1 -0
  27. package/dist/extractors/text.d.ts +6 -0
  28. package/dist/extractors/text.d.ts.map +1 -0
  29. package/dist/extractors/text.js +40 -0
  30. package/dist/extractors/text.js.map +1 -0
  31. package/dist/extractors/xlsx.d.ts +6 -0
  32. package/dist/extractors/xlsx.d.ts.map +1 -0
  33. package/dist/extractors/xlsx.js +59 -0
  34. package/dist/extractors/xlsx.js.map +1 -0
  35. package/dist/extractors/zip.d.ts +6 -0
  36. package/dist/extractors/zip.d.ts.map +1 -0
  37. package/dist/extractors/zip.js +25 -0
  38. package/dist/extractors/zip.js.map +1 -0
  39. package/dist/index.d.ts +14 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +181 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/types/index.d.ts +38 -0
  44. package/dist/types/index.d.ts.map +1 -0
  45. package/dist/types/index.js +3 -0
  46. package/dist/types/index.js.map +1 -0
  47. package/dist/utils/helpers.d.ts +13 -0
  48. package/dist/utils/helpers.d.ts.map +1 -0
  49. package/dist/utils/helpers.js +164 -0
  50. package/dist/utils/helpers.js.map +1 -0
  51. package/package.json +74 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sashi-does
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,221 @@
1
- # Temporary Holding Version
1
+ # doc-reader-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![CI](https://github.com/sashi-does/doc-reader-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/sashi-does/doc-reader-sdk/actions/workflows/ci.yml)
4
+ [![npm version](https://img.shields.io/npm/v/doc-reader-sdk.svg)](https://www.npmjs.com/package/doc-reader-sdk)
5
+ [![license: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
+ [![node](https://img.shields.io/node/v/doc-reader-sdk.svg)](package.json)
7
+
8
+ A universal TypeScript/Node.js SDK for extracting plain text from documents — one API for PDF, Word, Excel, PowerPoint, CSV, JSON and more, with automatic type detection, streaming for large files, and graceful fallback instead of thrown exceptions.
9
+
10
+ ```ts
11
+ import { readDoc } from 'doc-reader-sdk';
12
+
13
+ const result = await readDoc('quarterly-report.pdf');
14
+ console.log(result.content); // extracted text, ready for search, embeddings, an LLM prompt, etc.
15
+ ```
16
+
17
+ ## Contents
18
+
19
+ - [Why this exists](#why-this-exists)
20
+ - [Supported formats](#supported-formats)
21
+ - [Installation](#installation)
22
+ - [Usage](#usage)
23
+ - [API reference](#api-reference)
24
+ - [CLI](#cli)
25
+ - [Large file handling](#large-file-handling)
26
+ - [Type detection](#type-detection)
27
+ - [Architecture](#architecture)
28
+ - [Security](#security)
29
+ - [Contributing](#contributing)
30
+ - [License](#license)
31
+
32
+ ## Why this exists
33
+
34
+ Pulling text out of a document shouldn't require a different library — and a different mental model — for every file extension. doc-reader-sdk gives you one `read()` call that:
35
+
36
+ - **Detects the real format** from magic bytes, not just the file extension (so a renamed `.docx` still works).
37
+ - **Never throws on a malformed-but-plausible file.** Extractors degrade to a warning instead of an exception — you always get a result back.
38
+ - **Chunks content meaningfully** — per PDF page, per spreadsheet sheet, per slide, per JSONL record — so downstream consumers (search indexes, LLM context windows) can work chunk-by-chunk.
39
+ - **Streams instead of buffering** for text files over 10 MB.
40
+
41
+ ## Supported formats
42
+
43
+ | Format | Extension(s) | Notes |
44
+ |--------|-------------|-------|
45
+ | PDF | `.pdf` | Page-by-page or full text; warns on scanned/image-only PDFs or parser failures instead of throwing |
46
+ | Word | `.docx`, `.doc` | Full text via [mammoth](https://github.com/mwilliamson/mammoth.js) |
47
+ | Excel | `.xlsx`, `.xls` | Every sheet as CSV by default |
48
+ | PowerPoint | `.pptx`, `.ppt` | Slide-by-slide text extraction |
49
+ | CSV / TSV | `.csv`, `.tsv` | Streamed line-by-line |
50
+ | JSON | `.json` | Pretty-printed; falls back to raw text if invalid |
51
+ | JSONL | `.jsonl` | One chunk per record |
52
+ | Text / Markdown | `.txt`, `.md` | Auto-encoding detection; streams above 10 MB |
53
+ | HTML / XML | `.html`, `.htm`, `.xml` | Raw text preserved |
54
+ | RTF / EPUB | `.rtf`, `.epub` | Raw text extraction |
55
+ | ZIP | `.zip` | Lists archive contents by default |
56
+ | Unknown | any other extension | Best-effort text extraction with encoding detection |
57
+
58
+ ## Installation
59
+
60
+ ```bash
61
+ npm install doc-reader-sdk
62
+ ```
63
+
64
+ Requires Node.js 18+. The published package ships only compiled `dist/`, `README.md`, and `LICENSE` — no source, test fixtures, or dev tooling (see `files` in [package.json](package.json)).
65
+
66
+ ## Usage
67
+
68
+ ### One-shot
69
+
70
+ ```ts
71
+ import { readDoc } from 'doc-reader-sdk';
72
+
73
+ const result = await readDoc('report.pdf');
74
+ console.log(result.content); // full concatenated text
75
+ console.log(result.chunks); // per-page / per-sheet / per-slide chunks
76
+ console.log(result.charCount); // total characters
77
+ console.log(result.warnings); // non-fatal issues (encoding fallback, scanned PDF, etc.)
78
+ ```
79
+
80
+ ### Reusable instance with default options
81
+
82
+ ```ts
83
+ import { DocReader } from 'doc-reader-sdk';
84
+
85
+ const reader = new DocReader({
86
+ pageByPage: true, // PDF: extract per page
87
+ allSheets: true, // XLSX: extract all sheets
88
+ maxChars: 100_000, // truncate at 100k characters
89
+ });
90
+
91
+ const result = await reader.read('data.xlsx');
92
+ ```
93
+
94
+ Per-call options override the instance's defaults:
95
+
96
+ ```ts
97
+ await reader.read('other.xlsx', { allSheets: false }); // just this call, first sheet only
98
+ ```
99
+
100
+ ## API reference
101
+
102
+ ### `readDoc(filePath, options?): Promise<ExtractionResult>`
103
+
104
+ Convenience wrapper around `new DocReader().read(filePath, options)`.
105
+
106
+ ### `class DocReader`
107
+
108
+ ```ts
109
+ new DocReader(defaultOptions?: ExtractionOptions)
110
+ ```
111
+
112
+ ```ts
113
+ reader.read(filePath: string, options?: ExtractionOptions): Promise<ExtractionResult>
114
+ ```
115
+
116
+ ### `ExtractionOptions`
117
+
118
+ ```ts
119
+ interface ExtractionOptions {
120
+ maxChars?: number; // truncate output across chunks. Default: unlimited
121
+ pageByPage?: boolean; // PDF: per-page chunks. Default: false
122
+ allSheets?: boolean; // XLSX: include every sheet. Default: true
123
+ listOnly?: boolean; // ZIP: list entries only, don't extract. Default: true
124
+ encoding?: BufferEncoding; // force a text encoding instead of auto-detecting
125
+ streaming?: boolean; // force streaming mode. Default: true for files > 10 MB
126
+ chunkSize?: number; // stream chunk size in bytes. Default: 1 MB
127
+ }
128
+ ```
129
+
130
+ ### `ExtractionResult`
131
+
132
+ ```ts
133
+ interface ExtractionResult {
134
+ type: DocType; // detected format, e.g. "pdf" | "docx" | "xlsx" | ...
135
+ content: string; // full text, chunks joined with "\n\n"
136
+ chunks: DocChunk[]; // [{ index, content, source }]
137
+ charCount: number; // content.length
138
+ truncated: boolean; // true if maxChars cut content short
139
+ warnings: string[]; // non-fatal issues encountered during extraction
140
+ }
141
+ ```
142
+
143
+ ### `DocChunk`
144
+
145
+ ```ts
146
+ interface DocChunk {
147
+ index: number;
148
+ content: string;
149
+ source?: string; // "Page 3", "Sheet: Finance", "Slide 2", "Record 14", ...
150
+ }
151
+ ```
152
+
153
+ ## CLI
154
+
155
+ Installing the package also gives you a `doc-reader` binary:
156
+
157
+ ```bash
158
+ npx doc-reader report.pdf
159
+ npx doc-reader large.pdf --page-by-page --max-chars 50000
160
+ npx doc-reader data.xlsx --no-all-sheets
161
+ npx doc-reader archive.zip --list-only
162
+ npx doc-reader notes.docx --json # raw ExtractionResult as JSON
163
+ npx doc-reader --help
164
+ ```
165
+
166
+ Options mirror `ExtractionOptions`: `--max-chars <n>`, `--page-by-page`, `--no-all-sheets`, `--list-only`, `--json`.
167
+
168
+ ## Large file handling
169
+
170
+ - Text-based files **> 10 MB** automatically switch to streaming (override with the `streaming` option).
171
+ - PDFs are read into memory by `pdf-parse`; use `maxChars` to cap how much text you keep.
172
+ - CSV and JSONL are read line-by-line via Node streams and stop early once `maxChars` is reached.
173
+ - `maxChars` truncates across chunks, not just the first one — it cuts off exactly where the running total would exceed the limit.
174
+
175
+ ## Type detection
176
+
177
+ Detection runs in layers, so a misnamed file still resolves correctly:
178
+
179
+ 1. **Extension map** — fast path for known extensions.
180
+ 2. **Magic bytes** — reads the first 8 bytes to recognize PDF, OLE2 (legacy Office), and ZIP-based containers.
181
+ 3. **ZIP refinement** — for anything that matches the generic ZIP signature, inspects internal paths (`word/`, `xl/`, `ppt/`, `OEBPS/`) to tell DOCX, XLSX, PPTX and EPUB apart.
182
+
183
+ ## Architecture
184
+
185
+ ```
186
+ src/
187
+ index.ts DocReader class + readDoc() export
188
+ cli.ts CLI entry point
189
+ test.ts Fixture-based smoke test runner (npm run test:smoke)
190
+ types/index.ts ExtractionResult, DocChunk, ExtractionOptions, DocType
191
+ utils/helpers.ts type detection, encoding, streaming
192
+ extractors/
193
+ pdf.ts pdf-parse; catches parser failures and returns a warning
194
+ docx.ts mammoth
195
+ xlsx.ts xlsx (SheetJS)
196
+ pptx.ts adm-zip + regex text-node extraction over DrawingML
197
+ csv.ts readline streaming
198
+ json.ts JSON.parse + JSONL line-by-line
199
+ text.ts streaming read + iconv-lite encoding
200
+ zip.ts adm-zip manifest listing
201
+ ```
202
+
203
+ ## Security
204
+
205
+ doc-reader-sdk is designed to degrade gracefully rather than throw when a file is malformed, but parsing untrusted input (uploads, third-party documents) always carries some risk from the underlying parser libraries. See [SECURITY.md](SECURITY.md) for the current threat model, how to report a vulnerability, and known transitive-dependency advisories (`xlsx`/SheetJS has unpatched advisories on the npm registry; see that file for details and mitigations).
206
+
207
+ ## Contributing
208
+
209
+ Bug reports, format requests, and PRs are welcome — see [CONTRIBUTING.md](CONTRIBUTING.md) for the dev workflow and how to add a new format.
210
+
211
+ ```bash
212
+ npm install
213
+ npm run typecheck
214
+ npm test # vitest
215
+ npm run test:smoke # runs every file in test-fixtures/ through the CLI formatter
216
+ npm run build
217
+ ```
218
+
219
+ ## License
220
+
221
+ [MIT](LICENSE)
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,158 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ const path = __importStar(require("path"));
38
+ const fs = __importStar(require("fs"));
39
+ const index_js_1 = require("./index.js");
40
+ // ─── ANSI colours (no deps) ───────────────────────────────────────────────────
41
+ const C = {
42
+ reset: '\x1b[0m',
43
+ bold: '\x1b[1m',
44
+ dim: '\x1b[2m',
45
+ cyan: '\x1b[36m',
46
+ green: '\x1b[32m',
47
+ yellow: '\x1b[33m',
48
+ red: '\x1b[31m',
49
+ blue: '\x1b[34m',
50
+ gray: '\x1b[90m',
51
+ };
52
+ function c(color, text) {
53
+ return process.stdout.isTTY ? `${C[color]}${text}${C.reset}` : text;
54
+ }
55
+ function hr(char = '─', width = 72) {
56
+ return char.repeat(width);
57
+ }
58
+ function banner(result, filePath) {
59
+ const fileName = path.basename(filePath);
60
+ const fileSizeKB = (fs.statSync(filePath).size / 1024).toFixed(1);
61
+ console.log('\n' + c('cyan', hr('═')));
62
+ console.log(c('bold', ` ${fileName}`));
63
+ console.log(c('dim', ` Type: ${result.type.toUpperCase()} | Size: ${fileSizeKB} KB | Characters: ${result.charCount.toLocaleString()} | Chunks: ${result.chunks.length}`));
64
+ if (result.truncated) {
65
+ console.log(c('yellow', ` ⚠ Content truncated`));
66
+ }
67
+ if (result.warnings.length > 0) {
68
+ result.warnings.forEach(w => console.log(c('yellow', ` ⚠ ${w}`)));
69
+ }
70
+ console.log(c('cyan', hr('═')) + '\n');
71
+ }
72
+ function printResult(result) {
73
+ for (const chunk of result.chunks) {
74
+ if (result.chunks.length > 1) {
75
+ console.log(c('blue', hr('─')));
76
+ console.log(c('bold', ` ▸ ${chunk.source ?? `Chunk ${chunk.index + 1}`}`));
77
+ console.log(c('blue', hr('─')));
78
+ }
79
+ console.log(chunk.content);
80
+ console.log();
81
+ }
82
+ }
83
+ function usage() {
84
+ console.log(`
85
+ ${c('bold', 'doc-reader')} — Extract text from any document
86
+
87
+ ${c('bold', 'Usage:')}
88
+ npx tsx src/cli.ts <file> [options]
89
+
90
+ ${c('bold', 'Options:')}
91
+ --max-chars <n> Truncate output at N characters
92
+ --page-by-page (PDF) Show each page separately
93
+ --no-all-sheets (XLSX) Only read the first sheet
94
+ --list-only (ZIP) List archive contents only (default)
95
+ --json Output raw JSON instead of pretty-print
96
+ --help Show this help
97
+
98
+ ${c('bold', 'Examples:')}
99
+ npx tsx src/cli.ts report.pdf
100
+ npx tsx src/cli.ts data.xlsx
101
+ npx tsx src/cli.ts large.pdf --page-by-page --max-chars 50000
102
+ npx tsx src/cli.ts archive.zip --list-only
103
+ npx tsx src/cli.ts notes.docx --json
104
+ `);
105
+ }
106
+ // ─── Parse argv ───────────────────────────────────────────────────────────────
107
+ const args = process.argv.slice(2);
108
+ if (args.length === 0 || args.includes('--help')) {
109
+ usage();
110
+ process.exit(0);
111
+ }
112
+ const filePath = args[0];
113
+ const opts = {};
114
+ let jsonMode = false;
115
+ for (let i = 1; i < args.length; i++) {
116
+ const a = args[i];
117
+ if (a === '--max-chars' && args[i + 1]) {
118
+ opts.maxChars = parseInt(args[++i], 10);
119
+ }
120
+ else if (a === '--page-by-page') {
121
+ opts.pageByPage = true;
122
+ }
123
+ else if (a === '--no-all-sheets') {
124
+ opts.allSheets = false;
125
+ }
126
+ else if (a === '--list-only') {
127
+ opts.listOnly = true;
128
+ }
129
+ else if (a === '--json') {
130
+ jsonMode = true;
131
+ }
132
+ }
133
+ if (!fs.existsSync(filePath)) {
134
+ console.error(c('red', `✗ File not found: ${filePath}`));
135
+ process.exit(1);
136
+ }
137
+ // ─── Run ──────────────────────────────────────────────────────────────────────
138
+ (async () => {
139
+ try {
140
+ const reader = new index_js_1.DocReader(opts);
141
+ const result = await reader.read(filePath);
142
+ if (jsonMode) {
143
+ console.log(JSON.stringify(result, null, 2));
144
+ }
145
+ else {
146
+ banner(result, filePath);
147
+ printResult(result);
148
+ console.log(c('gray', `\nDone. ${result.charCount.toLocaleString()} characters extracted from ${result.chunks.length} chunk(s).\n`));
149
+ }
150
+ }
151
+ catch (err) {
152
+ console.error(c('red', `✗ Error: ${err.message}`));
153
+ if (process.env.DEBUG)
154
+ console.error(err);
155
+ process.exit(1);
156
+ }
157
+ })();
158
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAA6B;AAC7B,uCAAyB;AACzB,yCAAuC;AAGvC,iFAAiF;AACjF,MAAM,CAAC,GAAG;IACR,KAAK,EAAG,SAAS;IACjB,IAAI,EAAI,SAAS;IACjB,GAAG,EAAK,SAAS;IACjB,IAAI,EAAI,UAAU;IAClB,KAAK,EAAG,UAAU;IAClB,MAAM,EAAE,UAAU;IAClB,GAAG,EAAK,UAAU;IAClB,IAAI,EAAI,UAAU;IAClB,IAAI,EAAI,UAAU;CACnB,CAAC;AAEF,SAAS,CAAC,CAAC,KAAqB,EAAE,IAAY;IAC5C,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACtE,CAAC;AAED,SAAS,EAAE,CAAC,IAAI,GAAG,GAAG,EAAE,KAAK,GAAG,EAAE;IAChC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC;AAED,SAAS,MAAM,CAAC,MAAwB,EAAE,QAAgB;IACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACzC,MAAM,UAAU,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,C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AAC,MAAM,EAAE,WAAW,MAAM,CAAC,SAAS,CAAC,cAAc,EAAE,8BAA8B,MAAM,CAAC,MAAM,CAAC,MAAM,cAAc,CAAC,CAAC,CAAC;QACvI,CAAC;IACH,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,YAAa,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAC9D,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK;YAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC1C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,EAAE,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { DocChunk, ExtractionOptions } from '../types/index.js';
2
+ export declare function extractCsv(filePath: string, sep: string, opts: ExtractionOptions): Promise<{
3
+ chunks: DocChunk[];
4
+ warnings: string[];
5
+ }>;
6
+ //# sourceMappingURL=csv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csv.d.ts","sourceRoot":"","sources":["../../src/extractors/csv.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAErE,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC;IAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CA0BrD"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.extractCsv = extractCsv;
37
+ const fs = __importStar(require("fs"));
38
+ const readline = __importStar(require("readline"));
39
+ async function extractCsv(filePath, sep, opts) {
40
+ const warnings = [];
41
+ const lines = [];
42
+ const rl = readline.createInterface({
43
+ input: fs.createReadStream(filePath, { encoding: (opts.encoding ?? 'utf-8') }),
44
+ crlfDelay: Infinity,
45
+ });
46
+ for await (const line of rl) {
47
+ lines.push(line);
48
+ // Yield chunks to avoid memory blowout on giant CSVs
49
+ if (opts.maxChars && lines.join('\n').length > opts.maxChars) {
50
+ warnings.push(`CSV truncated at ${lines.length} rows due to maxChars limit.`);
51
+ break;
52
+ }
53
+ }
54
+ const header = lines[0] ?? '';
55
+ const cols = header.split(sep).length;
56
+ const content = lines.join('\n');
57
+ return {
58
+ chunks: [{ index: 0, content, source: `${lines.length} rows × ${cols} columns` }],
59
+ warnings,
60
+ };
61
+ }
62
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AAK,CAAC,MAAM,WAAW,IAAI,UAAU,EAAE,CAAC;QACjF,QAAQ;KACT,CAAC;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { DocChunk } from '../types/index.js';
2
+ export declare function extractDocx(filePath: string): Promise<{
3
+ chunks: DocChunk[];
4
+ warnings: string[];
5
+ }>;
6
+ //# sourceMappingURL=docx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docx.d.ts","sourceRoot":"","sources":["../../src/extractors/docx.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;IAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAiBrD"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.extractDocx = extractDocx;
40
+ const fs = __importStar(require("fs"));
41
+ const mammoth_1 = __importDefault(require("mammoth"));
42
+ async function extractDocx(filePath) {
43
+ const warnings = [];
44
+ const buf = fs.readFileSync(filePath);
45
+ const result = await mammoth_1.default.extractRawText({ buffer: buf });
46
+ if (result.messages.length > 0) {
47
+ result.messages.forEach(m => {
48
+ if (m.type === 'warning')
49
+ warnings.push(`mammoth: ${m.message}`);
50
+ });
51
+ }
52
+ const text = result.value.trim();
53
+ return {
54
+ chunks: [{ index: 0, content: text, source: 'Document' }],
55
+ warnings,
56
+ };
57
+ }
58
+ //# sourceMappingURL=docx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docx.js","sourceRoot":"","sources":["../../src/extractors/docx.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kCAmBC;AAvBD,uCAAyB;AACzB,sDAA8B;AAGvB,KAAK,UAAU,WAAW,CAC/B,QAAgB;IAEhB,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,MAAM,iBAAO,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IAE7D,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;YAC1B,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS;gBAAE,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QACnE,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACjC,OAAO;QACL,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;QACzD,QAAQ;KACT,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { DocChunk, ExtractionOptions } from '../types/index.js';
2
+ export declare function extractJson(filePath: string, opts: ExtractionOptions): Promise<{
3
+ chunks: DocChunk[];
4
+ warnings: string[];
5
+ }>;
6
+ export declare function extractJsonl(filePath: string, opts: ExtractionOptions): Promise<{
7
+ chunks: DocChunk[];
8
+ warnings: string[];
9
+ }>;
10
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/extractors/json.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAErE,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC;IAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAkBrD;AAED,wBAAsB,YAAY,CAChC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC;IAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAiCrD"}