jtcsv 1.1.0 → 2.1.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 +275 -317
- package/bin/jtcsv.js +171 -89
- package/cli-tui.js +0 -0
- package/csv-to-json.js +135 -22
- package/dist/jtcsv.cjs.js +1619 -0
- package/dist/jtcsv.cjs.js.map +1 -0
- package/dist/jtcsv.esm.js +1599 -0
- package/dist/jtcsv.esm.js.map +1 -0
- package/dist/jtcsv.umd.js +1625 -0
- package/dist/jtcsv.umd.js.map +1 -0
- package/examples/cli-tool.js +186 -0
- package/examples/express-api.js +167 -0
- package/examples/large-dataset-example.js +185 -0
- package/examples/plugin-excel-exporter.js +407 -0
- package/examples/simple-usage.js +280 -0
- package/examples/streaming-example.js +419 -0
- package/index.d.ts +22 -3
- package/index.js +1 -0
- package/json-save.js +1 -1
- package/json-to-csv.js +16 -6
- package/package.json +130 -16
- package/plugins/README.md +373 -0
- package/plugins/express-middleware/README.md +306 -0
- package/plugins/express-middleware/example.js +136 -0
- package/plugins/express-middleware/index.d.ts +114 -0
- package/plugins/express-middleware/index.js +360 -0
- package/plugins/express-middleware/package.json +52 -0
- package/plugins/fastify-plugin/index.js +406 -0
- package/plugins/fastify-plugin/package.json +55 -0
- package/plugins/nextjs-api/README.md +452 -0
- package/plugins/nextjs-api/examples/ConverterComponent.jsx +386 -0
- package/plugins/nextjs-api/examples/api-convert.js +69 -0
- package/plugins/nextjs-api/index.js +388 -0
- package/plugins/nextjs-api/package.json +63 -0
- package/plugins/nextjs-api/route.js +372 -0
- package/src/browser/browser-functions.js +189 -0
- package/src/browser/csv-to-json-browser.js +442 -0
- package/src/browser/errors-browser.js +194 -0
- package/src/browser/index.js +79 -0
- package/src/browser/json-to-csv-browser.js +309 -0
- package/src/browser/workers/csv-parser.worker.js +359 -0
- package/src/browser/workers/worker-pool.js +467 -0
- package/src/core/plugin-system.js +472 -0
- package/src/engines/fast-path-engine-new.js +338 -0
- package/src/engines/fast-path-engine.js +347 -0
- package/src/formats/ndjson-parser.js +419 -0
- package/src/index-with-plugins.js +349 -0
- package/stream-csv-to-json.js +1 -1
- package/stream-json-to-csv.js +1 -1
package/README.md
CHANGED
|
@@ -1,329 +1,286 @@
|
|
|
1
|
-
# jtcsv -
|
|
1
|
+
# jtcsv - Complete JSON ↔ CSV Converter
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Version 2.0** - Now with full browser support, Web Workers, and streaming!
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[jtcsv
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://www.npmjs.com/package/jtcsv
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
```bash
|
|
9
|
-
# Install globally with CLI and TUI support
|
|
10
|
-
npm install -g jtcsv
|
|
9
|
+
A lightweight, efficient, and secure library for converting between JSON and CSV formats with full browser support, Web Workers for large files, and streaming capabilities.
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
npm install jtcsv
|
|
14
|
-
```
|
|
11
|
+
## ✨ Features
|
|
15
12
|
|
|
16
|
-
###
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
### 🚀 Core Features
|
|
14
|
+
- **Bidirectional Conversion**: JSON ↔ CSV with full type preservation
|
|
15
|
+
- **Zero Dependencies**: Pure JavaScript/TypeScript, no external dependencies
|
|
16
|
+
- **TypeScript Support**: Full type definitions included
|
|
17
|
+
- **Security First**: Built-in CSV injection protection
|
|
18
|
+
- **RFC 4180 Compliant**: Proper CSV formatting and escaping
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
### 🌐 Browser Support
|
|
21
|
+
- **Full Browser Compatibility**: Chrome, Firefox, Safari, Edge, Mobile
|
|
22
|
+
- **Web Workers**: Process large files without blocking UI
|
|
23
|
+
- **File API Integration**: Direct file upload/download support
|
|
24
|
+
- **Streaming Processing**: Handle files of any size
|
|
25
|
+
- **Progress Tracking**: Real-time progress updates
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
### ⚡ Performance
|
|
28
|
+
- **High Speed**: Optimized parsing algorithms
|
|
29
|
+
- **Memory Efficient**: Streaming and chunked processing
|
|
30
|
+
- **Worker Pool**: Reusable Web Workers for parallel processing
|
|
31
|
+
- **Caching**: Intelligent caching for repeated operations
|
|
26
32
|
|
|
27
|
-
###
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
### 🔧 Advanced Features
|
|
34
|
+
- **Auto-detection**: Automatic delimiter detection
|
|
35
|
+
- **Custom Headers**: Flexible header mapping and renaming
|
|
36
|
+
- **Nested Objects**: Support for complex nested structures
|
|
37
|
+
- **Multiple Formats**: CSV, TSV, Excel-compatible output
|
|
38
|
+
- **Error Handling**: Comprehensive error reporting and recovery
|
|
31
39
|
|
|
32
|
-
|
|
33
|
-
npx jtcsv tui
|
|
34
|
-
```
|
|
40
|
+
## 📦 Installation
|
|
35
41
|
|
|
36
|
-
###
|
|
42
|
+
### Node.js
|
|
37
43
|
```bash
|
|
38
|
-
|
|
39
|
-
jtcsv json2csv input.json output.csv --delimiter=,
|
|
40
|
-
|
|
41
|
-
# Convert CSV to JSON
|
|
42
|
-
jtcsv csv2json input.csv output.json --parse-numbers
|
|
43
|
-
|
|
44
|
-
# Streaming for large files
|
|
45
|
-
jtcsv stream json2csv large.json output.csv --max-records=1000000
|
|
46
|
-
|
|
47
|
-
# Show help
|
|
48
|
-
jtcsv help
|
|
44
|
+
npm install jtcsv
|
|
49
45
|
```
|
|
50
46
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
- **CSV → JSON Streaming**: Real-time parsing with backpressure
|
|
56
|
-
- **Memory-efficient**: Constant memory usage regardless of file size
|
|
57
|
-
- **Progress monitoring**: Real-time progress tracking
|
|
47
|
+
### Browser (CDN)
|
|
48
|
+
```html
|
|
49
|
+
<!-- UMD version (global jtcsv variable) -->
|
|
50
|
+
<script src="https://cdn.jsdelivr.net/npm/jtcsvst/jtcsv.umd.js"></script>
|
|
58
51
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
- **Keyboard shortcuts**: Efficient navigation for power users
|
|
52
|
+
<!-- ESM version -->
|
|
53
|
+
<script type="module">
|
|
54
|
+
import { jsonToCsv } from 'https://cdn.jsdelivr.net/npm/jtcsvst/jtcsv.esm.js';
|
|
55
|
+
</script>
|
|
56
|
+
```
|
|
65
57
|
|
|
66
|
-
|
|
58
|
+
## 🚀 Quick Start
|
|
67
59
|
|
|
68
|
-
|
|
60
|
+
### Node.js Usage
|
|
69
61
|
```javascript
|
|
70
|
-
const {
|
|
62
|
+
const { jsonToCsv, csvToJson } = require('jtcsv
|
|
63
|
+
|
|
64
|
+
// JSON to CSV
|
|
65
|
+
const data = [
|
|
66
|
+
{ id: 1, name: 'John', email: 'john@example.com' },
|
|
67
|
+
{ id: 2, name: 'Jane', email: 'jane@example.com' }
|
|
68
|
+
];
|
|
71
69
|
|
|
72
|
-
|
|
73
|
-
const transformStream = createJsonToCsvStream({
|
|
70
|
+
const csv = jsonToCsv(data, {
|
|
74
71
|
delimiter: ',',
|
|
75
72
|
includeHeaders: true,
|
|
76
73
|
preventCsvInjection: true
|
|
77
74
|
});
|
|
78
75
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
console.log(csv);
|
|
77
|
+
// id,name,email
|
|
78
|
+
// 1,John,john@example.com
|
|
79
|
+
// 2,Jane,jane@example.com
|
|
82
80
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
// Create transform stream
|
|
88
|
-
const transformStream = createCsvToJsonStream({
|
|
81
|
+
// CSV to JSON
|
|
82
|
+
const csvString = 'id,name,email\n1,John,john@example.com\n2,Jane,jane@example.com';
|
|
83
|
+
const json = csvToJson(csvString, {
|
|
89
84
|
delimiter: ',',
|
|
90
|
-
parseNumbers: true
|
|
91
|
-
parseBooleans: true
|
|
85
|
+
parseNumbers: true
|
|
92
86
|
});
|
|
93
87
|
|
|
94
|
-
|
|
95
|
-
|
|
88
|
+
console.log(json);
|
|
89
|
+
// [
|
|
90
|
+
// { id: 1, name: 'John', email: 'john@example.com' },
|
|
91
|
+
// { id: 2, name: 'Jane', email: 'jane@example.com' }
|
|
92
|
+
// ]
|
|
96
93
|
```
|
|
97
94
|
|
|
98
|
-
###
|
|
99
|
-
|
|
100
|
-
#### **Interactive Interface**
|
|
101
|
-
```
|
|
102
|
-
┌─────────────────────────────────────────────────────────────┐
|
|
103
|
-
│ jtcsv - The Complete JSON↔CSV Converter │
|
|
104
|
-
│ Press Ctrl+S to Save | Ctrl+P to Preview | Ctrl+Q to Quit │
|
|
105
|
-
├─────────────────────────────────────────────────────────────┤
|
|
106
|
-
│ [JSON → CSV] [CSV → JSON] [Batch Process] [Settings] │
|
|
107
|
-
├─────────────────┬───────────────────────────────────────────┤
|
|
108
|
-
│ JSON Input │ CSV Output Preview │
|
|
109
|
-
│ [ ]│ id,name,email │
|
|
110
|
-
│ [ ]│ 1,John,john@example.com │
|
|
111
|
-
│ [ ]│ 2,Jane,jane@example.com │
|
|
112
|
-
├─────────────────┴───────────────────────────────────────────┤
|
|
113
|
-
│ Options: Delimiter: , | Headers: ✓ | Parse Numbers: ✗ │
|
|
114
|
-
├─────────────────────────────────────────────────────────────┤
|
|
115
|
-
│ Ready to convert JSON to CSV │
|
|
116
|
-
└─────────────────────────────────────────────────────────────┘
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
#### **TUI Navigation**
|
|
120
|
-
| Shortcut | Action | Description |
|
|
121
|
-
|----------|--------|-------------|
|
|
122
|
-
| `Tab` | Switch elements | Move between UI components |
|
|
123
|
-
| `Arrow Keys` | Navigate lists | Scroll through options |
|
|
124
|
-
| `Enter` | Select/Activate | Choose option or confirm |
|
|
125
|
-
| `Ctrl+S` | Save output | Save to file |
|
|
126
|
-
| `Ctrl+P` | Preview | Show conversion preview |
|
|
127
|
-
| `Ctrl+Q` | Quit | Exit application |
|
|
128
|
-
| `Esc` | Back | Return to main mode |
|
|
129
|
-
| `F1` | Help | Show help screen |
|
|
130
|
-
|
|
131
|
-
## 📊 **Complete Feature Comparison**
|
|
132
|
-
|
|
133
|
-
| Feature | jtcsv | PapaParse | csvtojson | json-2-csv |
|
|
134
|
-
|---------|-------|-----------|-----------|------------|
|
|
135
|
-
| **Size** | 8KB | 35KB | 45KB | 15KB |
|
|
136
|
-
| **Dependencies** | 0 | 0 | 1 | 2 |
|
|
137
|
-
| **JSON→CSV** | ✅ | ✅ | ❌ | ✅ |
|
|
138
|
-
| **CSV→JSON** | ✅ | ✅ | ✅ | ✅ |
|
|
139
|
-
| **Bidirectional Streaming** | ✅ | ⚠️ | ⚠️ | ❌ |
|
|
140
|
-
| **TUI Interface** | ✅ | ❌ | ❌ | ❌ |
|
|
141
|
-
| **CLI Tool** | ✅ | ❌ | ✅ | ✅ |
|
|
142
|
-
| **CSV Injection Protection** | ✅ | ⚠️ | ❌ | ❌ |
|
|
143
|
-
| **Path Traversal Protection** | ✅ | ❌ | ❌ | ❌ |
|
|
144
|
-
| **TypeScript** | ✅ | ✅ | ⚠️ | ✅ |
|
|
145
|
-
| **RFC 4180** | ✅ | ✅ | ✅ | ✅ |
|
|
146
|
-
| **Zero Dependencies** | ✅ | ✅ | ❌ | ❌ |
|
|
147
|
-
|
|
148
|
-
## 🚀 **Performance Benchmarks**
|
|
149
|
-
|
|
150
|
-
### **Memory Usage**
|
|
151
|
-
- **In-memory**: Up to 1 million records (configurable)
|
|
152
|
-
- **Streaming**: Unlimited size with constant memory
|
|
153
|
-
- **TUI**: < 50MB RAM for interface
|
|
154
|
-
|
|
155
|
-
### **Processing Speed**
|
|
156
|
-
```
|
|
157
|
-
10,000 records: ~15ms
|
|
158
|
-
100,000 records: ~120ms
|
|
159
|
-
1,000,000 records: ~1.2s
|
|
160
|
-
Streaming 1GB file: ~45s (22MB/s)
|
|
161
|
-
TUI response: < 100ms
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
### **Streaming Performance**
|
|
165
|
-
- **Throughput**: 20-50MB/s depending on complexity
|
|
166
|
-
- **Memory**: Constant ~10MB regardless of file size
|
|
167
|
-
- **CPU**: Single-threaded, efficient parsing
|
|
168
|
-
|
|
169
|
-
## 🛡️ **Enterprise-Grade Security**
|
|
170
|
-
|
|
171
|
-
### **CSV Injection Protection**
|
|
172
|
-
```javascript
|
|
173
|
-
// Dangerous data is automatically escaped
|
|
174
|
-
const dangerous = [
|
|
175
|
-
{ formula: '=HYPERLINK(\"http://evil.com\",\"Click\")' },
|
|
176
|
-
{ command: '@SUM(A1:A10)' }
|
|
177
|
-
];
|
|
178
|
-
|
|
179
|
-
const safeCsv = jsonToCsv(dangerous);
|
|
180
|
-
// Formulas are prefixed with ' to prevent execution
|
|
181
|
-
// Result: '=HYPERLINK(...) and '@SUM(A1:A10)
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
### **Path Traversal Protection**
|
|
185
|
-
```javascript
|
|
186
|
-
try {
|
|
187
|
-
// This will throw SecurityError
|
|
188
|
-
await saveAsCsv(data, '../../../etc/passwd.csv');
|
|
189
|
-
} catch (error) {
|
|
190
|
-
console.error('Security violation:', error.message);
|
|
191
|
-
}
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
### **Input Validation**
|
|
95
|
+
### Browser Usage
|
|
195
96
|
```javascript
|
|
196
|
-
//
|
|
197
|
-
jsonToCsv(
|
|
198
|
-
jsonToCsv([], { delimiter: 123 }); // throws ConfigurationError
|
|
199
|
-
jsonToCsv(largeArray, { maxRecords: 100 }); // throws LimitError if >100
|
|
200
|
-
```
|
|
97
|
+
// Using global variable (UMD)
|
|
98
|
+
const csv = window.jtcsv.jsonToCsv(data, { delimiter: ',' });
|
|
201
99
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
### **1. Large File Processing**
|
|
205
|
-
```javascript
|
|
206
|
-
const { createCsvFileToJsonStream } = require('jtcsv');
|
|
207
|
-
const fs = require('fs');
|
|
100
|
+
// Download as file
|
|
101
|
+
window.jtcsv.downloadAsCsv(data, 'export.csv', { delimiter: ',' });
|
|
208
102
|
|
|
209
|
-
//
|
|
210
|
-
const
|
|
103
|
+
// Parse uploaded file
|
|
104
|
+
const fileInput = document.querySelector('input[type="file"]');
|
|
105
|
+
const json = await window.jtcsv.parseCsvFile(fileInput.files[0], {
|
|
211
106
|
delimiter: ',',
|
|
212
|
-
parseNumbers: true
|
|
213
|
-
maxRows: Infinity // No limit for streaming
|
|
107
|
+
parseNumbers: true
|
|
214
108
|
});
|
|
215
109
|
|
|
216
|
-
//
|
|
217
|
-
|
|
110
|
+
// Use Web Workers for large files
|
|
111
|
+
const largeFile = document.querySelector('input[type="file"]').files[0];
|
|
112
|
+
const result = await window.jtcsv.parseCSVWithWorker(largeFile, {}, (progress) => {
|
|
113
|
+
console.log(`Progress: ${progress.percentage.toFixed(1)}%`);
|
|
114
|
+
});
|
|
218
115
|
```
|
|
219
116
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
117
|
+
## 🔧 API Reference
|
|
118
|
+
|
|
119
|
+
### Core Functions
|
|
120
|
+
|
|
121
|
+
#### `jsonToCsv(data, options)`
|
|
122
|
+
Converts an array of objects to CSV string.
|
|
123
|
+
|
|
124
|
+
**Options:**
|
|
125
|
+
- `delimiter` (string, default: ';'): CSV delimiter character
|
|
126
|
+
- `includeHeaders` (boolean, default: true): Include header row
|
|
127
|
+
- `renameMap` (object): Map for renaming column headers
|
|
128
|
+
- `preventCsvInjection` (boolean, default: true): Escape formulas for security
|
|
129
|
+
- `rfc4180Compliant` (boolean, default: true): RFC 4180 compliance
|
|
130
|
+
- `maxRecords` (number): Maximum records to process
|
|
131
|
+
|
|
132
|
+
#### `csvToJson(csv, options)`
|
|
133
|
+
Converts CSV string to array of objects.
|
|
134
|
+
|
|
135
|
+
**Options:**
|
|
136
|
+
- `delimiter` (string): Delimiter (auto-detected if not specified)
|
|
137
|
+
- `autoDetect` (boolean, default: true): Auto-detect delimiter
|
|
138
|
+
- `hasHeaders` (boolean, default: true): CSV has header row
|
|
139
|
+
- `parseNumbers` (boolean, default: false): Parse numeric values
|
|
140
|
+
- `parseBooleans` (boolean, default: false): Parse boolean values
|
|
141
|
+
- `trim` (boolean, default: true): Trim whitespace
|
|
142
|
+
- `maxRows` (number): Maximum rows to process
|
|
143
|
+
|
|
144
|
+
### Browser-Specific Functions
|
|
145
|
+
|
|
146
|
+
#### `downloadAsCsv(data, filename, options)`
|
|
147
|
+
Converts and downloads JSON as CSV file.
|
|
148
|
+
|
|
149
|
+
#### `parseCsvFile(file, options)`
|
|
150
|
+
Parses CSV File object to JSON.
|
|
151
|
+
|
|
152
|
+
#### `createCsvBlob(data, options)`
|
|
153
|
+
Creates CSV Blob without downloading.
|
|
154
|
+
|
|
155
|
+
#### `parseCsvBlob(blob, options)`
|
|
156
|
+
Parses CSV Blob to JSON.
|
|
157
|
+
|
|
158
|
+
### Web Workers Functions
|
|
159
|
+
|
|
160
|
+
#### `createWorkerPool(options)`
|
|
161
|
+
Creates a pool of Web Workers for parallel processing.
|
|
162
|
+
|
|
163
|
+
**Options:**
|
|
164
|
+
- `workerCount` (number, default: 4): Number of workers
|
|
165
|
+
- `maxQueueSize` (number, default: 100): Maximum queue size
|
|
166
|
+
- `autoScale` (boolean, default: true): Auto-scale workers
|
|
167
|
+
- `idleTimeout` (number, default: 60000): Idle timeout in ms
|
|
168
|
+
|
|
169
|
+
#### `parseCSVWithWorker(csvInput, options, onProgress)`
|
|
170
|
+
Parses CSV using Web Workers with progress tracking.
|
|
171
|
+
|
|
172
|
+
## 💡 Examples
|
|
173
|
+
|
|
174
|
+
### React Component Example
|
|
175
|
+
```jsx
|
|
176
|
+
import React, { useState } from 'react';
|
|
177
|
+
import { parseCsvFile, downloadAsCsv } from 'jtcsv
|
|
178
|
+
|
|
179
|
+
export function CSVProcessor() {
|
|
180
|
+
const [data, setData] = useState([]);
|
|
181
|
+
const [loading, setLoading] = useState(false);
|
|
182
|
+
|
|
183
|
+
const handleFileUpload = async (event) => {
|
|
184
|
+
const file = event.target.files[0];
|
|
185
|
+
if (!file) return;
|
|
186
|
+
|
|
187
|
+
setLoading(true);
|
|
188
|
+
try {
|
|
189
|
+
const jsonData = await parseCsvFile(file, {
|
|
190
|
+
delimiter: ',',
|
|
191
|
+
parseNumbers: true
|
|
192
|
+
});
|
|
193
|
+
setData(jsonData);
|
|
194
|
+
} catch (error) {
|
|
195
|
+
console.error('Error:', error);
|
|
196
|
+
} finally {
|
|
197
|
+
setLoading(false);
|
|
233
198
|
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const handleExport = () => {
|
|
202
|
+
downloadAsCsv(data, 'export.csv', { delimiter: ',' });
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
<div>
|
|
207
|
+
<input type="file" accept=".csv" onChange={handleFileUpload} />
|
|
208
|
+
<button onClick={handleExport} disabled={!data.length}>
|
|
209
|
+
Export to CSV
|
|
210
|
+
</button>
|
|
211
|
+
{loading && <div>Processing...</div>}
|
|
212
|
+
<pre>{JSON.stringify(data.slice(0, 5), null, 2)}</pre>
|
|
213
|
+
</div>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
239
216
|
```
|
|
240
217
|
|
|
241
|
-
###
|
|
218
|
+
### Large File Processing with Progress
|
|
242
219
|
```javascript
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
### **Integration with Editors**
|
|
268
|
-
```bash
|
|
269
|
-
# Use TUI from within VSCode terminal
|
|
270
|
-
# Or integrate with your favorite editor's terminal
|
|
220
|
+
import { parseCSVWithWorker } from 'jtcsv
|
|
221
|
+
|
|
222
|
+
async function processLargeFile(file) {
|
|
223
|
+
const progressBar = document.getElementById('progress-bar');
|
|
224
|
+
const status = document.getElementById('status');
|
|
225
|
+
|
|
226
|
+
try {
|
|
227
|
+
const result = await parseCSVWithWorker(file, {}, (progress) => {
|
|
228
|
+
const percent = Math.round(progress.percentage);
|
|
229
|
+
progressBar.style.width = percent + '%';
|
|
230
|
+
progressBar.textContent = percent + '%';
|
|
231
|
+
|
|
232
|
+
status.textContent =
|
|
233
|
+
`Processing: ${progress.processed.toLocaleString()} of ${progress.total.toLocaleString()} rows ` +
|
|
234
|
+
`(${Math.round(progress.speed)} rows/sec)`;
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
status.textContent = `Processed ${result.length.toLocaleString()} rows successfully`;
|
|
238
|
+
return result;
|
|
239
|
+
} catch (error) {
|
|
240
|
+
status.textContent = `Error: ${error.message}`;
|
|
241
|
+
throw error;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
271
244
|
```
|
|
272
245
|
|
|
273
|
-
|
|
246
|
+
### Security: CSV Injection Protection
|
|
247
|
+
```javascript
|
|
248
|
+
const dangerousData = [
|
|
249
|
+
{ formula: '=SUM(1,2)', command: '=cmd|"/c calc"!A1' }
|
|
250
|
+
];
|
|
274
251
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
├── examples/ # Usage examples
|
|
287
|
-
│ ├── streaming-example.js
|
|
288
|
-
│ ├── express-api.js
|
|
289
|
-
│ └── large-dataset-example.js
|
|
290
|
-
├── __tests__/ # Test suites
|
|
291
|
-
└── package.json
|
|
252
|
+
// With protection enabled (default)
|
|
253
|
+
const safeCsv = jsonToCsv(dangerousData, { preventCsvInjection: true });
|
|
254
|
+
// formula,command
|
|
255
|
+
// "'=SUM(1,2)","'=cmd|"/c calc"!A1"
|
|
256
|
+
// Formulas are prefixed with single quote to prevent execution
|
|
257
|
+
|
|
258
|
+
// Without protection
|
|
259
|
+
const unsafeCsv = jsonToCsv(dangerousData, { preventCsvInjection: false });
|
|
260
|
+
// formula,command
|
|
261
|
+
// =SUM(1,2),=cmd|"/c calc"!A1
|
|
262
|
+
// WARNING: This could execute commands in Excel!
|
|
292
263
|
```
|
|
293
264
|
|
|
294
|
-
##
|
|
265
|
+
## 📊 Performance
|
|
295
266
|
|
|
296
|
-
###
|
|
297
|
-
- **Enterprise applications** requiring security
|
|
298
|
-
- **Large file processing** (>100MB)
|
|
299
|
-
- **Real-time data pipelines**
|
|
300
|
-
- **Terminal/CLI workflows**
|
|
301
|
-
- **TypeScript projects**
|
|
302
|
-
- **Embedded systems** (zero dependencies)
|
|
303
|
-
- **Batch processing** automation
|
|
304
|
-
- **Data migration** tools
|
|
267
|
+
### Benchmark Results
|
|
305
268
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
269
|
+
| File Size | Rows | Without Workers | With Workers | Improvement |
|
|
270
|
+
|-----------|------|-----------------|--------------|-------------|
|
|
271
|
+
| 1 MB | 10K | 120 ms | 80 ms | 33% faster |
|
|
272
|
+
| 10 MB | 100K | 1.2 sec | 0.8 sec | 33% faster |
|
|
273
|
+
| 100 MB | 1M | 12 sec | 7 sec | 42% faster |
|
|
274
|
+
| 500 MB | 5M | 65 sec | 35 sec | 46% faster |
|
|
310
275
|
|
|
311
|
-
|
|
276
|
+
### Memory Usage
|
|
277
|
+
- **Without streaming**: Loads entire file into memory
|
|
278
|
+
- **With streaming**: Processes in chunks (default 10K rows)
|
|
279
|
+
- **With Web Workers**: Distributes memory across workers
|
|
312
280
|
|
|
313
|
-
|
|
314
|
-
```bash
|
|
315
|
-
# Run all tests
|
|
316
|
-
npm test
|
|
317
|
-
|
|
318
|
-
# Test with coverage
|
|
319
|
-
npm run test:coverage
|
|
320
|
-
|
|
321
|
-
# Run specific test suites
|
|
322
|
-
npm test -- --testPathPattern=streaming
|
|
323
|
-
npm test -- --testPathPattern=tui
|
|
324
|
-
```
|
|
281
|
+
## 🛠️ Development
|
|
325
282
|
|
|
326
|
-
###
|
|
283
|
+
### Building from Source
|
|
327
284
|
```bash
|
|
328
285
|
# Clone repository
|
|
329
286
|
git clone https://github.com/Linol-Hamelton/jtcsv.git
|
|
@@ -332,62 +289,63 @@ cd jtcsv
|
|
|
332
289
|
# Install dependencies
|
|
333
290
|
npm install
|
|
334
291
|
|
|
335
|
-
#
|
|
336
|
-
npm run
|
|
292
|
+
# Build browser version
|
|
293
|
+
npm run build
|
|
337
294
|
|
|
338
|
-
#
|
|
339
|
-
npm
|
|
295
|
+
# Run tests
|
|
296
|
+
npm test
|
|
297
|
+
|
|
298
|
+
# Start demo server
|
|
299
|
+
npm run demo
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### Project Structure
|
|
303
|
+
```
|
|
304
|
+
jtcsv/
|
|
305
|
+
├── src/browser/ # Browser-specific code
|
|
306
|
+
│ ├── index.js # Browser entry point
|
|
307
|
+
│ ├── *.js # Browser modules
|
|
308
|
+
│ └── workers/ # Web Workers implementation
|
|
309
|
+
├── dist/ # Built distributions
|
|
310
|
+
│ ├── jtcsv.umd.js # UMD bundle
|
|
311
|
+
│ ├── jtcsv.esm.js # ESM bundle
|
|
312
|
+
│ └── jtcsv.cjs.js # CJS bundle
|
|
313
|
+
├── demo/ # Demo application
|
|
314
|
+
├── __tests__/ # Test files
|
|
315
|
+
├── rollup.config.mjs # Build configuration
|
|
316
|
+
└── package.json # Project configuration
|
|
340
317
|
```
|
|
341
318
|
|
|
342
|
-
## 🤝
|
|
319
|
+
## 🤝 Contributing
|
|
320
|
+
|
|
321
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
343
322
|
|
|
344
323
|
1. Fork the repository
|
|
345
|
-
2. Create
|
|
346
|
-
3. Add
|
|
347
|
-
4.
|
|
348
|
-
5.
|
|
324
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
325
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
326
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
327
|
+
5. Open a Pull Request
|
|
349
328
|
|
|
350
|
-
|
|
351
|
-
- Maintain 100% test coverage
|
|
352
|
-
- Follow existing code style
|
|
353
|
-
- Add TypeScript definitions for new features
|
|
354
|
-
- Update documentation
|
|
355
|
-
- Consider security implications
|
|
329
|
+
## 📄 License
|
|
356
330
|
|
|
357
|
-
|
|
331
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
358
332
|
|
|
359
|
-
|
|
333
|
+
## 🙏 Acknowledgments
|
|
360
334
|
|
|
361
|
-
|
|
335
|
+
- Inspired by the need for secure, efficient CSV processing in browsers
|
|
336
|
+
- Thanks to all contributors who have helped improve this library
|
|
337
|
+
- Special thanks to the open source community for invaluable tools and libraries
|
|
362
338
|
|
|
363
|
-
|
|
364
|
-
- **npm**: https://www.npmjs.com/package/jtcsv
|
|
365
|
-
- **Issues**: https://github.com/Linol-Hamelton/jtcsv/issues
|
|
366
|
-
- **TUI Documentation**: ./TUI-README.md
|
|
339
|
+
## 📞 Support
|
|
367
340
|
|
|
368
|
-
|
|
341
|
+
- **GitHub Issues**: [Report bugs or request features](https://github.com/Linol-Hamelton/jtcsv/issues)
|
|
342
|
+
- **Documentation**: [Full API documentation](https://github.com/Linol-Hamelton/jtcsv#readme)
|
|
343
|
+
- **Examples**: [Example code and demos](https://github.com/Linol-Hamelton/jtcsv/tree/main/demo)
|
|
369
344
|
|
|
370
|
-
|
|
345
|
+
---
|
|
371
346
|
|
|
372
|
-
|
|
373
|
-
1. **Zero Dependencies** - Perfect for production and embedded use
|
|
374
|
-
2. **Bidirectional Streaming** - Handle files of any size
|
|
375
|
-
3. **TUI Interface** - User-friendly terminal experience
|
|
376
|
-
4. **Enterprise Security** - Built-in protection against attacks
|
|
377
|
-
5. **Complete Solution** - From simple conversions to complex pipelines
|
|
347
|
+
**Happy coding!** If you find this library useful, please consider giving it a star on GitHub ⭐
|
|
378
348
|
|
|
379
|
-
### **Competitive Advantage**
|
|
380
|
-
- **vs PapaParse**: Better security, TUI interface, zero dependencies
|
|
381
|
-
- **vs csvtojson**: Bidirectional conversion, streaming, security
|
|
382
|
-
- **vs json-2-csv**: Streaming API, TUI, better performance
|
|
383
349
|
|
|
384
|
-
### **Future Roadmap**
|
|
385
|
-
- **Plugin system** for extended functionality
|
|
386
|
-
- **Web interface** for browser-based usage
|
|
387
|
-
- **Database connectors** for direct import/export
|
|
388
|
-
- **Cloud integration** for serverless workflows
|
|
389
|
-
- **Machine learning** for automatic schema detection
|
|
390
350
|
|
|
391
|
-
---
|
|
392
351
|
|
|
393
|
-
**Ready for production with enterprise-grade features and unmatched flexibility.**
|