convert-csv-to-json 3.27.0 โ 4.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/CHANGELOG.md +41 -1
- package/README.md +173 -833
- package/RELEASE_NOTES.md +320 -0
- package/RFC4180_MIGRATION_GUIDE.md +737 -0
- package/docs/ASYNC.md +485 -0
- package/docs/BROWSER.md +425 -0
- package/docs/ERROR_HANDLING.md +367 -0
- package/docs/MAPROWS.md +196 -0
- package/docs/SYNC.md +239 -0
- package/index.d.ts +10 -8
- package/index.js +13 -10
- package/package.json +1 -1
- package/src/browserApi.js +29 -6
- package/src/csvToJson.js +233 -82
- package/src/csvToJsonAsync.js +15 -1
- package/src/util/errors.js +227 -0
- package/src/util/fileUtils.js +18 -7
- package/src/util/jsonUtils.js +3 -1
- /package/{MIGRATION.md โ MIGRATION_TO_ASYNC.md} +0 -0
package/RELEASE_NOTES.md
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
# Release Notes - RFC 4180 Compliance Update
|
|
2
|
+
|
|
3
|
+
## Version 3.21.0 - RFC 4180 Compliance
|
|
4
|
+
|
|
5
|
+
### Overview
|
|
6
|
+
This release makes csvToJson **fully compliant with RFC 4180**, the standard format specification for CSV files. This is a significant update that improves standards compliance, reliability, and compatibility with CSV data from various sources.
|
|
7
|
+
|
|
8
|
+
**RFC 4180** (Common Format and MIME Type for Comma-Separated Values (CSV) Files) is the official standard specification for CSV file formatting, maintained by the Internet Engineering Task Force (IETF).
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## ๐ Key Features
|
|
13
|
+
|
|
14
|
+
### 1. **RFC 4180 Compliant CSV Parsing**
|
|
15
|
+
- Full support for RFC 4180 standard CSV format
|
|
16
|
+
- Proper handling of quoted fields with embedded delimiters
|
|
17
|
+
- Support for multi-line fields (fields containing newlines)
|
|
18
|
+
- Correct quote escaping using double quotes (`""`)
|
|
19
|
+
|
|
20
|
+
### 2. **Default Comma Delimiter (Breaking Change)**
|
|
21
|
+
- **NEW**: Comma (`,`) is now the default field delimiter (RFC 4180 standard)
|
|
22
|
+
- **BREAKING**: Previous default was semicolon (`;`)
|
|
23
|
+
- Allows parsing standard CSV files without explicit configuration
|
|
24
|
+
- Maintains backward compatibility through explicit `fieldDelimiter()` calls
|
|
25
|
+
|
|
26
|
+
### 3. **Improved Quoted Field Handling**
|
|
27
|
+
- Properly handles fields wrapped in quotes
|
|
28
|
+
- Correctly processes escaped quotes within quoted fields
|
|
29
|
+
- Supports empty quoted fields (`""`)
|
|
30
|
+
- Handles fields containing delimiters, newlines, and special characters
|
|
31
|
+
|
|
32
|
+
### 4. **Line Ending Support**
|
|
33
|
+
- Support for CRLF (`\r\n`) - Windows standard
|
|
34
|
+
- Support for LF (`\n`) - Unix/Linux standard
|
|
35
|
+
- Support for CR (`\r`) - older Mac standard
|
|
36
|
+
- Automatic detection and handling
|
|
37
|
+
|
|
38
|
+
### 5. **Code Quality Improvements**
|
|
39
|
+
- Refactored for better readability and maintainability
|
|
40
|
+
- Added comprehensive JSDoc comments
|
|
41
|
+
- Extracted complex logic into focused helper methods
|
|
42
|
+
- Removed deprecated `substr()` method (replaced with `slice()`)
|
|
43
|
+
- Added braces to all conditional statements
|
|
44
|
+
- Removed deprecated `jsonToCsv()` function
|
|
45
|
+
|
|
46
|
+
### 6. **Comprehensive Test Coverage**
|
|
47
|
+
- 12 new RFC 4180 compliance tests
|
|
48
|
+
- 12 new comma-delimiter tests
|
|
49
|
+
- 109 total tests (up from 94)
|
|
50
|
+
- Edge case handling verification
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## โ ๏ธ Breaking Changes
|
|
55
|
+
|
|
56
|
+
### 1. **Default Delimiter Changed to Comma**
|
|
57
|
+
|
|
58
|
+
**BEFORE:**
|
|
59
|
+
```javascript
|
|
60
|
+
const csvToJson = require('convert-csv-to-json');
|
|
61
|
+
// Default delimiter was semicolon (;)
|
|
62
|
+
let result = csvToJson.getJsonFromCsv('data.csv');
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**AFTER (RFC 4180 standard):**
|
|
66
|
+
```javascript
|
|
67
|
+
const csvToJson = require('convert-csv-to-json');
|
|
68
|
+
// Default delimiter is now comma (,)
|
|
69
|
+
let result = csvToJson.getJsonFromCsv('data.csv');
|
|
70
|
+
// File should be comma-delimited
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Migration**: If your CSV files use semicolons or other delimiters, explicitly set the delimiter:
|
|
74
|
+
```javascript
|
|
75
|
+
csvToJson.fieldDelimiter(';').getJsonFromCsv('data.csv');
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 2. **Removed Deprecated Function**
|
|
79
|
+
|
|
80
|
+
The `jsonToCsv()` function has been **removed**. This was a deprecated alias.
|
|
81
|
+
|
|
82
|
+
**BEFORE:**
|
|
83
|
+
```javascript
|
|
84
|
+
csvToJson.jsonToCsv('input.csv', 'output.json');
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**AFTER:**
|
|
88
|
+
```javascript
|
|
89
|
+
csvToJson.generateJsonFileFromCsv('input.csv', 'output.json');
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 3. **Stricter Quoted Field Parsing**
|
|
93
|
+
|
|
94
|
+
RFC 4180 compliant quote handling may parse some edge cases differently:
|
|
95
|
+
|
|
96
|
+
**Example - Proper Quote Escaping:**
|
|
97
|
+
```javascript
|
|
98
|
+
// Input CSV: "name","description"
|
|
99
|
+
// "John","He said ""Hello"""
|
|
100
|
+
// Note: Double quotes "" represent a single quote
|
|
101
|
+
|
|
102
|
+
// Before: Might include literal quote characters
|
|
103
|
+
// After (RFC 4180): Correctly unescapes to: He said "Hello"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## ๐ Migration Guide
|
|
109
|
+
|
|
110
|
+
### Quick Start for Existing Users
|
|
111
|
+
|
|
112
|
+
**No changes needed if you:**
|
|
113
|
+
- Already explicitly set field delimiters with `.fieldDelimiter()`
|
|
114
|
+
- Use quoted field support with `.supportQuotedField(true)`
|
|
115
|
+
|
|
116
|
+
**Action required if you:**
|
|
117
|
+
- Rely on semicolon (`;`) as default delimiter
|
|
118
|
+
- Use the removed `jsonToCsv()` function
|
|
119
|
+
- Parse CSV files with quoted fields containing special characters
|
|
120
|
+
|
|
121
|
+
### Step-by-Step Migration
|
|
122
|
+
|
|
123
|
+
#### Step 1: Update Delimiter Usage
|
|
124
|
+
If your files use a special delimiter, add explicit configuration:
|
|
125
|
+
|
|
126
|
+
```javascript
|
|
127
|
+
// For semicolon-delimited files
|
|
128
|
+
csvToJson.fieldDelimiter(';').getJsonFromCsv('data.csv');
|
|
129
|
+
|
|
130
|
+
// For tab-delimited files
|
|
131
|
+
csvToJson.fieldDelimiter('\t').getJsonFromCsv('data.csv');
|
|
132
|
+
|
|
133
|
+
// For pipe-delimited files
|
|
134
|
+
csvToJson.fieldDelimiter('|').getJsonFromCsv('data.csv');
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### Step 2: Replace Deprecated Functions
|
|
138
|
+
Replace any usage of `jsonToCsv()`:
|
|
139
|
+
|
|
140
|
+
```javascript
|
|
141
|
+
// Old code
|
|
142
|
+
csvToJson.jsonToCsv('input.csv', 'output.json');
|
|
143
|
+
|
|
144
|
+
// New code
|
|
145
|
+
csvToJson.generateJsonFileFromCsv('input.csv', 'output.json');
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### Step 3: Test with RFC 4180 CSV Files
|
|
149
|
+
Test parsing standard CSV files without explicit delimiter:
|
|
150
|
+
|
|
151
|
+
```javascript
|
|
152
|
+
// This now works with standard CSV files (comma-delimited)
|
|
153
|
+
let result = csvToJson.getJsonFromCsv('standard.csv');
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## ๐ Feature Comparison
|
|
159
|
+
|
|
160
|
+
| Feature | Before | After |
|
|
161
|
+
|---------|--------|-------|
|
|
162
|
+
| Default Delimiter | `;` (semicolon) | `,` (comma) - RFC 4180 |
|
|
163
|
+
| Quoted Fields | Partial support | Full RFC 4180 support |
|
|
164
|
+
| Multi-line Fields | Not supported | Fully supported |
|
|
165
|
+
| Empty Quoted Fields | Issues | Correctly handled |
|
|
166
|
+
| Quote Escaping | Partial | RFC 4180 compliant (`""`) |
|
|
167
|
+
| Line Endings | Limited | CRLF, LF, CR all supported |
|
|
168
|
+
| Code Quality | Basic | Refactored & maintainable |
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## ๐งช Testing
|
|
173
|
+
|
|
174
|
+
All changes have been validated with comprehensive test coverage:
|
|
175
|
+
|
|
176
|
+
- **109+ tests** across 13 test suites
|
|
177
|
+
- **RFC 4180 compliance tests** - 15 tests
|
|
178
|
+
- **Comma delimiter tests** - 12 tests
|
|
179
|
+
- **Backward compatibility tests** - All existing tests pass
|
|
180
|
+
|
|
181
|
+
Run tests:
|
|
182
|
+
```bash
|
|
183
|
+
npm test # All tests with coverage
|
|
184
|
+
npm test -- --no-coverage # Quick test run
|
|
185
|
+
npm test test/rfc4180.spec.js # RFC 4180 tests only
|
|
186
|
+
npm test test/comma-delimiter.spec.js # Comma delimiter tests
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## ๐ Documentation
|
|
192
|
+
|
|
193
|
+
### New Resources
|
|
194
|
+
- **Comprehensive RFC 4180 Migration Guide** - See `RFC4180_MIGRATION_GUIDE.md`
|
|
195
|
+
- **RFC 4180 Compliance Tests** - See `test/rfc4180.spec.js`
|
|
196
|
+
- **Comma Delimiter Tests** - See `test/comma-delimiter.spec.js`
|
|
197
|
+
|
|
198
|
+
### RFC 4180 Standard
|
|
199
|
+
- Official RFC 4180 specification: https://tools.ietf.org/html/rfc4180
|
|
200
|
+
- Key points:
|
|
201
|
+
- Comma is the field delimiter
|
|
202
|
+
- Quoted fields with embedded delimiters/newlines
|
|
203
|
+
- Double quotes escape quotes within fields
|
|
204
|
+
- CRLF line endings recommended
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## ๐ Backward Compatibility
|
|
209
|
+
|
|
210
|
+
**Partially Compatible** - Most applications will work without changes if they:
|
|
211
|
+
- Already use `.fieldDelimiter()` explicitly
|
|
212
|
+
- Use `.supportQuotedField(true)` for quoted fields
|
|
213
|
+
- Don't rely on the removed `jsonToCsv()` function
|
|
214
|
+
|
|
215
|
+
**Requires Updates** if you:
|
|
216
|
+
- Rely on semicolon as default delimiter
|
|
217
|
+
- Parse semicolon-delimited CSV files without explicit configuration
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## ๐ก Examples
|
|
222
|
+
|
|
223
|
+
### Example 1: Parse Standard CSV File (Default Comma)
|
|
224
|
+
```javascript
|
|
225
|
+
const csvToJson = require('convert-csv-to-json');
|
|
226
|
+
|
|
227
|
+
// CSV file: name,age,city
|
|
228
|
+
// John,30,NYC
|
|
229
|
+
// Jane,25,LA
|
|
230
|
+
|
|
231
|
+
let result = csvToJson.getJsonFromCsv('data.csv');
|
|
232
|
+
// [{ name: 'John', age: '30', city: 'NYC' },
|
|
233
|
+
// { name: 'Jane', age: '25', city: 'LA' }]
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Example 2: Parse CSV String with Quoted Fields
|
|
237
|
+
```javascript
|
|
238
|
+
let csv = 'name,email,status\n' +
|
|
239
|
+
'"Smith, John","john@example.com","Active"\n' +
|
|
240
|
+
'"Doe, Jane","jane@example.com","Inactive"\n';
|
|
241
|
+
|
|
242
|
+
let result = csvToJson.supportQuotedField(true).csvStringToJson(csv);
|
|
243
|
+
// [{ name: 'Smith, John', email: 'john@example.com', status: 'Active' },
|
|
244
|
+
// { name: 'Doe, Jane', email: 'jane@example.com', status: 'Inactive' }]
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Example 3: Parse Multi-line Fields
|
|
248
|
+
```javascript
|
|
249
|
+
let csv = 'id,description\n' +
|
|
250
|
+
'1,"This is a\nmulti-line\ndescription"\n' +
|
|
251
|
+
'2,"Single line"\n';
|
|
252
|
+
|
|
253
|
+
let result = csvToJson.supportQuotedField(true).csvStringToJson(csv);
|
|
254
|
+
// [{ id: '1', description: 'This is a\nmulti-line\ndescription' },
|
|
255
|
+
// { id: '2', description: 'Single line' }]
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Example 4: Migrate from Semicolon-Delimited
|
|
259
|
+
```javascript
|
|
260
|
+
// For backward compatibility with semicolon-delimited files
|
|
261
|
+
let result = csvToJson.fieldDelimiter(';').getJsonFromCsv('data.csv');
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## ๐ Bug Fixes
|
|
267
|
+
|
|
268
|
+
- Fixed handling of empty quoted fields (`""`)
|
|
269
|
+
- Fixed multi-line field parsing within quoted regions
|
|
270
|
+
- Fixed quote escaping detection (RFC 4180 compliant)
|
|
271
|
+
- Fixed line ending detection (CRLF, LF, CR)
|
|
272
|
+
- Removed deprecated `substr()` usage
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## โจ Internal Improvements
|
|
277
|
+
|
|
278
|
+
- **Refactored `parseRecords()` method** - Clearer line-ending detection with `getLineEndingLength()` helper
|
|
279
|
+
- **Refactored `split()` method** - Extracted quote handling into `isEscapedQuote()` and `isEmptyQuotedField()` helpers
|
|
280
|
+
- **Named constants** - `QUOTE_CHAR`, `CRLF`, `LF`, `CR` for clarity
|
|
281
|
+
- **JSDoc comments** - Comprehensive documentation for all complex methods
|
|
282
|
+
- **Code consistency** - All if statements now have braces
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## ๐ฆ Installation
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
npm install convert-csv-to-json@latest
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Or update existing installation:
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
npm update convert-csv-to-json
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
## ๐ค Support
|
|
301
|
+
|
|
302
|
+
For issues, questions, or migration assistance:
|
|
303
|
+
- GitHub Issues: https://github.com/iuccio/csvToJson/issues
|
|
304
|
+
- GitHub Discussions: https://github.com/iuccio/csvToJson/discussions
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
## ๐ Changelog
|
|
309
|
+
|
|
310
|
+
**v3.21.0** (2026-03-17)
|
|
311
|
+
- โจ RFC 4180 compliance achieved
|
|
312
|
+
- ๐ Default delimiter changed to comma
|
|
313
|
+
- ๐งน Code refactored for maintainability
|
|
314
|
+
- โ
109+ comprehensive tests
|
|
315
|
+
- ๐ Full documentation updates
|
|
316
|
+
- โ ๏ธ Removed deprecated `jsonToCsv()` function
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
**Thank you for using csvToJson! We believe this RFC 4180 update makes the library more standards-compliant and reliable for real-world CSV parsing needs.**
|