jtcsv 2.1.0 → 2.1.3
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 +63 -17
- package/bin/jtcsv.js +1013 -117
- package/csv-to-json.js +385 -311
- package/examples/simple-usage.js +2 -3
- package/index.d.ts +288 -5
- package/index.js +23 -0
- package/json-to-csv.js +130 -89
- package/package.json +47 -19
- package/plugins/README.md +146 -2
- package/plugins/hono/README.md +25 -0
- package/plugins/hono/index.d.ts +12 -0
- package/plugins/hono/index.js +36 -0
- package/plugins/hono/package.json +35 -0
- package/plugins/nestjs/README.md +33 -0
- package/plugins/nestjs/index.d.ts +25 -0
- package/plugins/nestjs/index.js +77 -0
- package/plugins/nestjs/package.json +37 -0
- package/plugins/nuxt/README.md +25 -0
- package/plugins/nuxt/index.js +21 -0
- package/plugins/nuxt/package.json +35 -0
- package/plugins/nuxt/runtime/composables/useJtcsv.js +6 -0
- package/plugins/nuxt/runtime/plugin.js +6 -0
- package/plugins/remix/README.md +26 -0
- package/plugins/remix/index.d.ts +16 -0
- package/plugins/remix/index.js +62 -0
- package/plugins/remix/package.json +35 -0
- package/plugins/sveltekit/README.md +28 -0
- package/plugins/sveltekit/index.d.ts +17 -0
- package/plugins/sveltekit/index.js +54 -0
- package/plugins/sveltekit/package.json +33 -0
- package/plugins/trpc/README.md +22 -0
- package/plugins/trpc/index.d.ts +7 -0
- package/plugins/trpc/index.js +32 -0
- package/plugins/trpc/package.json +34 -0
- package/src/core/delimiter-cache.js +186 -0
- package/src/core/transform-hooks.js +350 -0
- package/src/engines/fast-path-engine.js +829 -340
- package/src/formats/tsv-parser.js +336 -0
- package/src/index-with-plugins.js +36 -14
- package/cli-tui.js +0 -5
package/README.md
CHANGED
|
@@ -4,15 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
[jtcsv
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
|
-
[](https://www.npmjs.com/package/jtcsv
|
|
8
8
|
|
|
9
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.
|
|
10
|
+
Zero-deps core with optional add-ons (TUI, Excel) for advanced workflows.
|
|
10
11
|
|
|
11
12
|
## ✨ Features
|
|
12
13
|
|
|
13
14
|
### 🚀 Core Features
|
|
14
15
|
- **Bidirectional Conversion**: JSON ↔ CSV with full type preservation
|
|
15
|
-
- **Zero
|
|
16
|
+
- **Zero-Deps Core**: Pure JavaScript/TypeScript core with optional add-ons
|
|
16
17
|
- **TypeScript Support**: Full type definitions included
|
|
17
18
|
- **Security First**: Built-in CSV injection protection
|
|
18
19
|
- **RFC 4180 Compliant**: Proper CSV formatting and escaping
|
|
@@ -37,6 +38,14 @@ A lightweight, efficient, and secure library for converting between JSON and CSV
|
|
|
37
38
|
- **Multiple Formats**: CSV, TSV, Excel-compatible output
|
|
38
39
|
- **Error Handling**: Comprehensive error reporting and recovery
|
|
39
40
|
|
|
41
|
+
### 🔌 Framework Integrations (Optional)
|
|
42
|
+
- **NestJS**: `@jtcsv/nestjs`
|
|
43
|
+
- **Remix**: `@jtcsv/remix`
|
|
44
|
+
- **Nuxt**: `@jtcsv/nuxt`
|
|
45
|
+
- **SvelteKit**: `@jtcsv/sveltekit`
|
|
46
|
+
- **Hono**: `@jtcsv/hono`
|
|
47
|
+
- **tRPC**: `@jtcsv/trpc`
|
|
48
|
+
|
|
40
49
|
## 📦 Installation
|
|
41
50
|
|
|
42
51
|
### Node.js
|
|
@@ -44,6 +53,15 @@ A lightweight, efficient, and secure library for converting between JSON and CSV
|
|
|
44
53
|
npm install jtcsv
|
|
45
54
|
```
|
|
46
55
|
|
|
56
|
+
### Optional add-ons
|
|
57
|
+
```bash
|
|
58
|
+
# Terminal UI
|
|
59
|
+
npm install @jtcsv/tui
|
|
60
|
+
|
|
61
|
+
# Excel plugin
|
|
62
|
+
npm install @jtcsv/excel exceljs
|
|
63
|
+
```
|
|
64
|
+
|
|
47
65
|
### Browser (CDN)
|
|
48
66
|
```html
|
|
49
67
|
<!-- UMD version (global jtcsv variable) -->
|
|
@@ -133,6 +151,7 @@ Converts an array of objects to CSV string.
|
|
|
133
151
|
Converts CSV string to array of objects.
|
|
134
152
|
|
|
135
153
|
**Options:**
|
|
154
|
+
Fast path parsing is the default pipeline; use `fastPathMode` to control row shape.
|
|
136
155
|
- `delimiter` (string): Delimiter (auto-detected if not specified)
|
|
137
156
|
- `autoDetect` (boolean, default: true): Auto-detect delimiter
|
|
138
157
|
- `hasHeaders` (boolean, default: true): CSV has header row
|
|
@@ -140,6 +159,22 @@ Converts CSV string to array of objects.
|
|
|
140
159
|
- `parseBooleans` (boolean, default: false): Parse boolean values
|
|
141
160
|
- `trim` (boolean, default: true): Trim whitespace
|
|
142
161
|
- `maxRows` (number): Maximum rows to process
|
|
162
|
+
- `useFastPath` (boolean, default: true): Enable fast-path parser (set `false` to force quote-aware path)
|
|
163
|
+
- `fastPathMode` (string, default: 'objects'): `'objects'` for object rows, `'compact'` for arrays (lower memory), `'stream'` to return an async iterator
|
|
164
|
+
|
|
165
|
+
#### `csvToJsonIterator(csv, options)`
|
|
166
|
+
Convert CSV to JSON rows as an async iterator for large inputs.
|
|
167
|
+
You can also call `csvToJson(csv, { fastPathMode: 'stream' })` to get the same async iterator.
|
|
168
|
+
|
|
169
|
+
**Example:**
|
|
170
|
+
```javascript
|
|
171
|
+
const { csvToJsonIterator } = require('jtcsv');
|
|
172
|
+
|
|
173
|
+
const csv = 'id,name\n1,Jane\n2,John';
|
|
174
|
+
for await (const row of csvToJsonIterator(csv, { fastPathMode: 'compact' })) {
|
|
175
|
+
console.log(row);
|
|
176
|
+
}
|
|
177
|
+
```
|
|
143
178
|
|
|
144
179
|
### Browser-Specific Functions
|
|
145
180
|
|
|
@@ -264,19 +299,34 @@ const unsafeCsv = jsonToCsv(dangerousData, { preventCsvInjection: false });
|
|
|
264
299
|
|
|
265
300
|
## 📊 Performance
|
|
266
301
|
|
|
267
|
-
### Benchmark Results
|
|
302
|
+
### Benchmark Results (Node.js 22, 10K rows/records)
|
|
303
|
+
|
|
304
|
+
**CSV → JSON (10K rows)**
|
|
305
|
+
|
|
306
|
+
| Library | Time | Memory | Rank |
|
|
307
|
+
|---------|------|--------|------|
|
|
308
|
+
| **JTCSV (FastPath Compact)** | 16.79 ms | 4.47 MB | 🥇 1st |
|
|
309
|
+
| **JTCSV (FastPath Stream)** | 18.27 ms | 6.03 MB | 🥈 2nd |
|
|
310
|
+
| **JTCSV** | 19.76 ms | 8.96 MB | 🥉 3rd |
|
|
311
|
+
| PapaParse | 21.57 ms | 6.97 MB | 4th |
|
|
312
|
+
| csv-parser | 30.52 ms | 6.53 MB | 5th |
|
|
313
|
+
|
|
314
|
+
**JSON → CSV (10K records)**
|
|
315
|
+
|
|
316
|
+
| Library | Time | Memory | Rank |
|
|
317
|
+
|---------|------|--------|------|
|
|
318
|
+
| **JTCSV** | 11.21 ms | 4.77 MB | 🥇 1st |
|
|
319
|
+
| json2csv | 12.27 ms | 12.11 MB | 🥈 2nd |
|
|
268
320
|
|
|
269
|
-
|
|
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 |
|
|
321
|
+
### Scaling (JTCSV only)
|
|
275
322
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
323
|
+
| Rows/Records | CSV→JSON Time (FastPath Compact) | JSON→CSV Time (JTCSV) | CSV→JSON Memory | JSON→CSV Memory |
|
|
324
|
+
|--------------|----------------------------------|-----------------------|-----------------|-----------------|
|
|
325
|
+
| 1,000 | 2.06 ms | 1.04 ms | 2.15 MB | 0.52 MB |
|
|
326
|
+
| 10,000 | 14.68 ms | 8.23 ms | 2.11 MB | 4.14 MB |
|
|
327
|
+
| 100,000 | 164.18 ms | 90.93 ms | 44.93 MB | 34.79 MB |
|
|
328
|
+
|
|
329
|
+
See `BENCHMARK-RESULTS.md` and `docs/PERFORMANCE.md` for environment details and methodology.
|
|
280
330
|
|
|
281
331
|
## 🛠️ Development
|
|
282
332
|
|
|
@@ -345,7 +395,3 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
345
395
|
---
|
|
346
396
|
|
|
347
397
|
**Happy coding!** If you find this library useful, please consider giving it a star on GitHub ⭐
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|