@f-o-t/ofx 2.1.0 → 2.2.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 +56 -0
- package/dist/index.d.ts +269 -79
- package/dist/index.js +359 -12
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -260,6 +260,62 @@ console.log("Accounts:", result.accounts);
|
|
|
260
260
|
console.log("Balances:", result.balances);
|
|
261
261
|
```
|
|
262
262
|
|
|
263
|
+
### Batch Streaming Functions
|
|
264
|
+
|
|
265
|
+
For processing multiple OFX files in a single operation with progress tracking.
|
|
266
|
+
|
|
267
|
+
#### `parseBatchStream(files): AsyncGenerator<BatchStreamEvent>`
|
|
268
|
+
|
|
269
|
+
Parses multiple OFX files sequentially, yielding events as they are parsed. Ideal for importing multiple bank statements at once.
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
import { parseBatchStream, type BatchFileInput } from "@fot/ofx";
|
|
273
|
+
import { readFileSync } from "node:fs";
|
|
274
|
+
|
|
275
|
+
const files: BatchFileInput[] = [
|
|
276
|
+
{ filename: "january.ofx", buffer: new Uint8Array(readFileSync("january.ofx")) },
|
|
277
|
+
{ filename: "february.ofx", buffer: new Uint8Array(readFileSync("february.ofx")) },
|
|
278
|
+
{ filename: "march.ofx", buffer: new Uint8Array(readFileSync("march.ofx")) },
|
|
279
|
+
];
|
|
280
|
+
|
|
281
|
+
for await (const event of parseBatchStream(files)) {
|
|
282
|
+
switch (event.type) {
|
|
283
|
+
case "file_start":
|
|
284
|
+
console.log(`Processing: ${event.filename}`);
|
|
285
|
+
break;
|
|
286
|
+
case "transaction":
|
|
287
|
+
console.log(`File ${event.fileIndex}: ${event.data.NAME} - ${event.data.TRNAMT}`);
|
|
288
|
+
break;
|
|
289
|
+
case "file_complete":
|
|
290
|
+
console.log(`Completed ${event.filename}: ${event.transactionCount} transactions`);
|
|
291
|
+
break;
|
|
292
|
+
case "file_error":
|
|
293
|
+
console.error(`Error in ${event.filename}: ${event.error}`);
|
|
294
|
+
break;
|
|
295
|
+
case "batch_complete":
|
|
296
|
+
console.log(`Batch done: ${event.totalTransactions} transactions from ${event.totalFiles} files`);
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
#### `parseBatchStreamToArray(files): Promise<BatchParsedFile[]>`
|
|
303
|
+
|
|
304
|
+
Collects all batch results into an array for easier processing.
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
import { parseBatchStreamToArray } from "@fot/ofx";
|
|
308
|
+
|
|
309
|
+
const results = await parseBatchStreamToArray(files);
|
|
310
|
+
|
|
311
|
+
for (const file of results) {
|
|
312
|
+
console.log(`${file.filename}: ${file.transactions.length} transactions`);
|
|
313
|
+
if (file.error) {
|
|
314
|
+
console.error(` Error: ${file.error}`);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
263
319
|
## Encoding Support
|
|
264
320
|
|
|
265
321
|
The library automatically detects and handles various character encodings commonly used in OFX files, especially from Brazilian banks.
|