bai2-to-excel 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.
package/README.md CHANGED
@@ -1,3 +1,36 @@
1
- # Temporary Holding Version
1
+ # bai2-to-excel
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
+ Zero-dependency JavaScript / TypeScript parser and CSV converter for **BAI2 corporate bank statements** (Chase, Bank of America, Wells Fargo, Citi, HSBC, Barclays).
4
+
5
+ > **Need multi-tab Excel (.xlsx), Xero, QuickBooks (QBO), or batch conversion without coding?**
6
+ > Use the online converter at **[radarbg.com/instant/bai2-to-excel](https://radarbg.com/instant/bai2-to-excel?ref=npm-bai2)** · [Download free BAI2 sample file](https://radarbg.com/samples/bai2-sample-file?ref=npm-bai2)
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install bai2-to-excel
12
+ ```
13
+
14
+ ## Usage (Node.js / TypeScript)
15
+
16
+ ```js
17
+ const fs = require('fs');
18
+ const { parseBai2, toCsv } = require('bai2-to-excel');
19
+
20
+ const parsed = parseBai2(fs.readFileSync('statement.bai2', 'utf8'));
21
+ console.log(parsed.transactions);
22
+ fs.writeFileSync('statement.csv', toCsv(parsed));
23
+ ```
24
+
25
+ ## CLI
26
+
27
+ ```bash
28
+ npx bai2-to-excel statement.bai2 > statement.csv
29
+ npx bai2-to-excel statement.bai2 --json
30
+ ```
31
+
32
+ ## Related Online Accounting Tools (Zero Install)
33
+ - [BAI2 to Excel / Xero / QuickBooks](https://radarbg.com/instant/bai2-to-excel?ref=npm-bai2)
34
+ - [Bank Statement PDF to Excel](https://radarbg.com/instant/bank-statement-pdf-to-excel?ref=npm-bai2)
35
+ - [Free Sample Bank Statement Files (9 Formats)](https://radarbg.com/samples?ref=npm-bai2)
36
+ - [Free Accounting Excel Templates](https://radarbg.com/templates?ref=npm-bai2)
package/cli.js ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ const fs = require('fs');
4
+ const { parseBai2, toCsv } = require('./index');
5
+ const file = process.argv[2];
6
+ if (!file || file === '-h' || file === '--help') {
7
+ console.log('Usage: bai2-to-excel <statement.bai2> [--json]');
8
+ console.log('Online Excel / Xero / QuickBooks converter: https://radarbg.com/instant/bai2-to-excel?ref=npm-bai2');
9
+ process.exit(0);
10
+ }
11
+ const parsed = parseBai2(fs.readFileSync(file, 'utf8'));
12
+ if (process.argv.includes('--json')) console.log(JSON.stringify(parsed, null, 2));
13
+ else process.stdout.write(toCsv(parsed));
package/index.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ export interface Bai2Transaction {
2
+ accountNumber: string;
3
+ currency: string;
4
+ typeCode: string;
5
+ typeLabel: string;
6
+ amount: number;
7
+ bankRef: string;
8
+ customerRef: string;
9
+ description: string;
10
+ }
11
+ export interface Bai2Account {
12
+ accountNumber: string;
13
+ currency: string;
14
+ transactions: Bai2Transaction[];
15
+ }
16
+ export interface Bai2Statement {
17
+ accounts: Bai2Account[];
18
+ transactions: Bai2Transaction[];
19
+ }
20
+ export declare const TYPE_CODES: Record<string, string>;
21
+ export declare function parseBai2(text: string): Bai2Statement;
22
+ export declare function toCsv(parsed: Bai2Statement): string;
package/index.js ADDED
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+
3
+ const TYPE_CODES = {
4
+ '165': 'Preauthorized ACH Credit',
5
+ '195': 'Incoming Money Transfer',
6
+ '455': 'Preauthorized ACH Debit',
7
+ '475': 'Check Paid',
8
+ '495': 'Outgoing Money Transfer',
9
+ '698': 'Miscellaneous Fee',
10
+ };
11
+
12
+ function parseBai2(text) {
13
+ const lines = String(text || '').replace(/\r\n/g, '\n').split('\n').map(l => l.trim()).filter(Boolean);
14
+ const accounts = [];
15
+ let curAcc = null;
16
+ let lastTx = null;
17
+
18
+ for (const line of lines) {
19
+ const clean = line.endsWith('/') ? line.slice(0, -1) : line;
20
+ const parts = clean.split(',');
21
+ const rec = parts[0];
22
+ if (rec === '03') {
23
+ curAcc = { accountNumber: parts[1] || '', currency: parts[2] || 'USD', transactions: [] };
24
+ accounts.push(curAcc);
25
+ lastTx = null;
26
+ } else if (rec === '16') {
27
+ if (!curAcc) {
28
+ curAcc = { accountNumber: '', currency: 'USD', transactions: [] };
29
+ accounts.push(curAcc);
30
+ }
31
+ const typeCode = parts[1] || '';
32
+ const rawAmt = parseInt(parts[2] || '0', 10) || 0;
33
+ const isDebit = typeCode.startsWith('4') || typeCode.startsWith('5') || typeCode.startsWith('6');
34
+ const amount = Number(((isDebit ? -rawAmt : rawAmt) / 100).toFixed(2));
35
+ lastTx = {
36
+ accountNumber: curAcc.accountNumber,
37
+ currency: curAcc.currency,
38
+ typeCode,
39
+ typeLabel: TYPE_CODES[typeCode] || 'Transaction',
40
+ amount,
41
+ bankRef: parts[4] || '',
42
+ customerRef: parts[5] || '',
43
+ description: parts.slice(6).join(',').trim(),
44
+ };
45
+ curAcc.transactions.push(lastTx);
46
+ } else if (rec === '88' && lastTx) {
47
+ const cont = parts.slice(1).join(',').trim();
48
+ if (cont) lastTx.description = (lastTx.description + ' ' + cont).trim();
49
+ }
50
+ }
51
+ const transactions = accounts.flatMap(a => a.transactions);
52
+ return { accounts, transactions };
53
+ }
54
+
55
+ function toCsv(parsed) {
56
+ const header = ['Account', 'Currency', 'TypeCode', 'TypeLabel', 'Amount', 'BankRef', 'CustomerRef', 'Description'];
57
+ const esc = v => '"' + String(v == null ? '' : v).replace(/"/g, '""') + '"';
58
+ const rows = [header.join(',')];
59
+ for (const t of parsed.transactions || []) {
60
+ rows.push([t.accountNumber, t.currency, t.typeCode, t.typeLabel, t.amount.toFixed(2), t.bankRef, t.customerRef, t.description].map(esc).join(','));
61
+ }
62
+ return rows.join('\n') + '\n';
63
+ }
64
+
65
+ module.exports = { parseBai2, toCsv, TYPE_CODES };
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "bai2-to-excel",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Zero-dependency BAI2 corporate bank statement parser and CSV converter (Chase, BofA, Citi, HSBC)",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "bin": {
8
+ "bai2-to-excel": "cli.js"
9
+ },
10
+ "scripts": {
11
+ "test": "node test.js"
12
+ },
13
+ "keywords": [
14
+ "bai2",
15
+ "bank-statement",
16
+ "excel",
17
+ "csv",
18
+ "treasury",
19
+ "accounting",
20
+ "fintech",
21
+ "chase",
22
+ "xero",
23
+ "quickbooks"
24
+ ],
25
+ "author": "RadarBG (https://radarbg.com)",
26
+ "license": "MIT",
27
+ "homepage": "https://radarbg.com/instant/bai2-to-excel?ref=npm-bai2",
28
+ "bugs": {
29
+ "url": "https://radarbg.com/support?ref=npm-bai2"
30
+ },
31
+ "engines": {
32
+ "node": ">=14.0.0"
33
+ },
34
+ "files": [
35
+ "index.js",
36
+ "index.d.ts",
37
+ "cli.js",
38
+ "README.md"
39
+ ]
40
+ }