convert-csv-to-json 4.14.0 → 4.16.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/.github/workflows/ci-cd.yml +1 -1
- package/docs/.nojekyll +0 -0
- package/docs/README.md +44 -0
- package/docs/demo.bundle.js +1708 -0
- package/docs/index.html +536 -0
- package/eslint.config.js +1 -1
- package/package.json +5 -1
- package/docs/api/BrowserApi.html +0 -2662
- package/docs/api/BrowserApiError.html +0 -669
- package/docs/api/ConfigurationError.html +0 -745
- package/docs/api/CsvFormatError.html +0 -677
- package/docs/api/CsvParsingError.html +0 -511
- package/docs/api/CsvToJson.html +0 -3367
- package/docs/api/CsvToJsonAsync.html +0 -2880
- package/docs/api/FileOperationError.html +0 -382
- package/docs/api/FileUtils.html +0 -1150
- package/docs/api/InputValidationError.html +0 -407
- package/docs/api/JsonUtil.html +0 -452
- package/docs/api/JsonValidationError.html +0 -357
- package/docs/api/StringUtils.html +0 -833
- package/docs/api/global.html +0 -3498
- package/docs/api/index.html +0 -414
- package/docs/api/index.js.html +0 -447
- package/docs/api/scripts/app.min.js +0 -1
- package/docs/api/scripts/linenumber.js +0 -26
- package/docs/api/scripts/search.js +0 -39
- package/docs/api/src_browserApi.js.html +0 -362
- package/docs/api/src_csvToJson.js.html +0 -696
- package/docs/api/src_csvToJsonAsync.js.html +0 -335
- package/docs/api/src_util_errors.js.html +0 -472
- package/docs/api/src_util_fileUtils.js.html +0 -238
- package/docs/api/src_util_jsonUtils.js.html +0 -166
- package/docs/api/src_util_stringUtils.js.html +0 -306
- package/docs/api/styles/app.min.css +0 -1
- package/docs/api/styles/iframe.css +0 -13
- package/docs/api/styles/prettify-jsdoc.css +0 -111
- package/docs/api/styles/prettify-tomorrow.css +0 -132
- package/docs/api/styles/reset.css +0 -44
package/docs/api/index.html
DELETED
|
@@ -1,414 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
|
|
6
|
-
<meta charset="utf-8">
|
|
7
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
8
|
-
<title> Home</title>
|
|
9
|
-
|
|
10
|
-
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script>
|
|
11
|
-
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
|
|
12
|
-
<script src="./build/entry.js"></script>
|
|
13
|
-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
|
14
|
-
<!--[if lt IE 9]>
|
|
15
|
-
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
16
|
-
<![endif]-->
|
|
17
|
-
<link href="https://fonts.googleapis.com/css?family=Roboto:100,400,700|Inconsolata,700" rel="stylesheet">
|
|
18
|
-
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
|
|
19
|
-
<link type="text/css" rel="stylesheet" href="https://jmblog.github.io/color-themes-for-google-code-prettify/themes/tomorrow-night.min.css">
|
|
20
|
-
<link type="text/css" rel="stylesheet" href="styles/app.min.css">
|
|
21
|
-
<link type="text/css" rel="stylesheet" href="styles/iframe.css">
|
|
22
|
-
<link type="text/css" rel="stylesheet" href="./node_modules/better-docs/css/better-docs.css">
|
|
23
|
-
<script async defer src="https://buttons.github.io/buttons.js"></script>
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
</head>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<body class="layout small-header">
|
|
31
|
-
<div id="stickyNavbarOverlay"></div>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
<div class="top-nav">
|
|
35
|
-
<div class="inner">
|
|
36
|
-
<a id="hamburger" role="button" class="navbar-burger" aria-label="menu" aria-expanded="false">
|
|
37
|
-
<span aria-hidden="true"></span>
|
|
38
|
-
<span aria-hidden="true"></span>
|
|
39
|
-
<span aria-hidden="true"></span>
|
|
40
|
-
</a>
|
|
41
|
-
<div class="logo">
|
|
42
|
-
|
|
43
|
-
<a class="image" href="index.html">
|
|
44
|
-
<img src="https://raw.githubusercontent.com/iuccio/CSVtoJSON/master/CSVtoJSON.png" alt="logo">
|
|
45
|
-
</a>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
<a href="index.html">
|
|
49
|
-
<h1 class="navbar-item">Convert CSV to JSON</h1>
|
|
50
|
-
</a>
|
|
51
|
-
|
|
52
|
-
</div>
|
|
53
|
-
<div class="menu">
|
|
54
|
-
|
|
55
|
-
<div class="navigation">
|
|
56
|
-
<a
|
|
57
|
-
href="index.html"
|
|
58
|
-
class="link"
|
|
59
|
-
>
|
|
60
|
-
Documentation
|
|
61
|
-
</a>
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
<a
|
|
66
|
-
class="link user-link "
|
|
67
|
-
href="https://github.com/iuccio/CSVtoJSON"
|
|
68
|
-
>
|
|
69
|
-
GitHub
|
|
70
|
-
</a>
|
|
71
|
-
|
|
72
|
-
<a
|
|
73
|
-
class="link user-link "
|
|
74
|
-
href="https://www.npmjs.com/package/convert-csv-to-json"
|
|
75
|
-
>
|
|
76
|
-
NPM
|
|
77
|
-
</a>
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
</div>
|
|
82
|
-
</div>
|
|
83
|
-
</div>
|
|
84
|
-
</div>
|
|
85
|
-
<div id="main">
|
|
86
|
-
<div
|
|
87
|
-
class="sidebar "
|
|
88
|
-
id="sidebarNav"
|
|
89
|
-
>
|
|
90
|
-
|
|
91
|
-
<nav>
|
|
92
|
-
|
|
93
|
-
<h2><a href="index.html">Documentation</a></h2><div class="category"></div><div class="category"><h2>1-Core API</h2><h3>Global</h3><ul><li><a href="global.html#asciiEncoding">asciiEncoding</a></li><li><a href="global.html#base64Encoding">base64Encoding</a></li><li><a href="global.html#csvStringToJson">csvStringToJson</a></li><li><a href="global.html#csvStringToJsonStringified">csvStringToJsonStringified</a></li><li><a href="global.html#csvToJsonAsync">csvToJsonAsync</a></li><li><a href="global.html#customEncoding">customEncoding</a></li><li><a href="global.html#fieldDelimiter">fieldDelimiter</a></li><li><a href="global.html#formatValueByType">formatValueByType</a></li><li><a href="global.html#generateJsonFileFromCsv">generateJsonFileFromCsv</a></li><li><a href="global.html#getJsonFromCsv">getJsonFromCsv</a></li><li><a href="global.html#hexEncoding">hexEncoding</a></li><li><a href="global.html#indexHeader">indexHeader</a></li><li><a href="global.html#latin1Encoding">latin1Encoding</a></li><li><a href="global.html#mapRows">mapRows</a></li><li><a href="global.html#parseSubArray">parseSubArray</a></li><li><a href="global.html#supportQuotedField">supportQuotedField</a></li><li><a href="global.html#trimHeaderFieldWhiteSpace">trimHeaderFieldWhiteSpace</a></li><li><a href="global.html#ucs2Encoding">ucs2Encoding</a></li><li><a href="global.html#utf16leEncoding">utf16leEncoding</a></li><li><a href="global.html#utf8Encoding">utf8Encoding</a></li></ul></div><div class="category"><h2>2-Sync</h2><h3>Classes</h3><ul><li><a href="CsvToJson.html">CsvToJson</a></li></ul></div><div class="category"><h2>3-Async</h2><h3>Classes</h3><ul><li><a href="CsvToJsonAsync.html">CsvToJsonAsync</a></li></ul></div><div class="category"><h2>4-Browser</h2><h3>Classes</h3><ul><li><a href="BrowserApi.html">BrowserApi</a></li></ul></div><div class="category"><h2>Error Classes</h2><h3>Classes</h3><ul><li><a href="BrowserApiError.html">BrowserApiError</a></li><li><a href="ConfigurationError.html">ConfigurationError</a></li><li><a href="CsvFormatError.html">CsvFormatError</a></li><li><a href="CsvParsingError.html">CsvParsingError</a></li><li><a href="FileOperationError.html">FileOperationError</a></li><li><a href="InputValidationError.html">InputValidationError</a></li><li><a href="JsonValidationError.html">JsonValidationError</a></li></ul></div><div class="category"><h2>Utilities</h2><h3>Classes</h3><ul><li><a href="FileUtils.html">FileUtils</a></li><li><a href="JsonUtil.html">JsonUtil</a></li><li><a href="StringUtils.html">StringUtils</a></li></ul></div>
|
|
94
|
-
|
|
95
|
-
</nav>
|
|
96
|
-
</div>
|
|
97
|
-
<div class="core" id="main-content-wrapper">
|
|
98
|
-
<div class="content">
|
|
99
|
-
<header class="page-title">
|
|
100
|
-
<p></p>
|
|
101
|
-
<h1>Home</h1>
|
|
102
|
-
</header>
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
<h3> </h3>
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
<section>
|
|
127
|
-
<article><h1>CSVtoJSON</h1>
|
|
128
|
-
<p><a href="https://github.com/iuccio/csvToJson/actions/workflows/ci-cd.yml"><img src="https://github.com/iuccio/csvToJson/actions/workflows/ci-cd.yml/badge.svg?branch=master" alt="Node CI"></a>
|
|
129
|
-
<img src="https://github.com/iuccio/csvToJson/actions/workflows/codeql-analysis.yml/badge.svg" alt="CodeQL">
|
|
130
|
-
<a href="https://snyk.io/test/github/iuccio/csvToJson"><img src="https://snyk.io/test/github/iuccio/csvToJson/badge.svg" alt="Known Vulnerabilities"></a>
|
|
131
|
-
<a href="https://codeclimate.com/github/iuccio/csvToJson"><img src="https://codeclimate.com/github/iuccio/csvToJson/badges/gpa.svg" alt="Code Climate"></a>
|
|
132
|
-
<a href="https://npmjs.org/package/convert-csv-to-json"><img src="https://img.shields.io/npm/v/convert-csv-to-json.svg" alt="NPM Version"></a>
|
|
133
|
-
<img src="https://img.shields.io/badge/nodeJS-%3E=18.x-brightgreen.svg" alt="NodeJS Version">
|
|
134
|
-
<a href="https://npmjs.org/package/convert-csv-to-json"><img src="https://img.shields.io/npm/dm/convert-csv-to-json.svg" alt="Downloads"></a>
|
|
135
|
-
<a href="https://npmjs.org/package/convert-csv-to-json"><img src="https://img.shields.io/npm/dt/convert-csv-to-json.svg?style=flat" alt="NPM total downloads"></a>
|
|
136
|
-
<a href="https://socket.dev/npm/package/convert-csv-to-json"><img src="https://badge.socket.dev/npm/package/convert-csv-to-json/3.20.0" alt="Socket Badge"></a></p>
|
|
137
|
-
<p><img src="https://img.shields.io/badge/node.js-6DA55F?style=for-the-badge&logo=node.js&logoColor=white" alt="NodeJS">
|
|
138
|
-
<img src="https://img.shields.io/badge/browser-supported-brightgreen.svg?style=for-the-badge&logo=google-chrome&logoColor=white" alt="Browser Support">
|
|
139
|
-
<img src="https://img.shields.io/badge/javascript-%23323330.svg?style=for-the-badge&logo=javascript&logoColor=%23F7DF1E" alt="JavaScript">
|
|
140
|
-
<img src="https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white" alt="TypeScript"></p>
|
|
141
|
-
<blockquote></blockquote>
|
|
142
|
-
<p>Convert CSV files to JSON with <strong>no dependencies</strong>. Supports Node.js (Sync & Async), and Browser environments with full RFC 4180 compliance.</p>
|
|
143
|
-
<h2>Overview</h2>
|
|
144
|
-
<p>Transform CSV data into JSON with a simple, chainable API. Choose your implementation style:</p>
|
|
145
|
-
<ul>
|
|
146
|
-
<li><strong><a href="docs/SYNC.md">Synchronous API</a></strong> - Blocking operations for simple workflows</li>
|
|
147
|
-
<li><strong><a href="docs/ASYNC.md">Asynchronous API</a></strong> - Promise-based for modern async/await patterns</li>
|
|
148
|
-
<li><strong><a href="docs/BROWSER.md">Browser API</a></strong> - Client-side CSV parsing for web applications</li>
|
|
149
|
-
</ul>
|
|
150
|
-
<h2>Features</h2>
|
|
151
|
-
<p>✅ <strong>RFC 4180 Compliant</strong> - Proper handling of quoted fields, delimiters, newlines, and escape sequences<br>
|
|
152
|
-
✅ <strong>Zero Dependencies</strong> - No external packages required<br>
|
|
153
|
-
✅ <strong>Full TypeScript Support</strong> - Included type definitions for all APIs<br>
|
|
154
|
-
✅ <strong>Flexible Configuration</strong> - Custom delimiters, encoding, trimming, and more<br>
|
|
155
|
-
✅ <strong>Method Chaining</strong> - Fluent API for readable code<br>
|
|
156
|
-
✅ <strong>Large File Support</strong> - Stream processing for memory-efficient handling<br>
|
|
157
|
-
✅ <strong>Comprehensive Error Handling</strong> - Detailed, actionable error messages with solutions (see <a href="docs/ERROR_HANDLING.md">ERROR_HANDLING.md</a>)</p>
|
|
158
|
-
<h2>RFC 4180 Standard</h2>
|
|
159
|
-
<p><strong><a href="https://datatracker.ietf.org/doc/html/rfc4180">RFC 4180</a></strong> is the IETF standard specification for CSV (Comma-Separated Values) files. This library is fully compliant with RFC 4180, ensuring proper handling of:</p>
|
|
160
|
-
<table>
|
|
161
|
-
<thead>
|
|
162
|
-
<tr>
|
|
163
|
-
<th>Aspect</th>
|
|
164
|
-
<th>RFC 4180 Specification</th>
|
|
165
|
-
</tr>
|
|
166
|
-
</thead>
|
|
167
|
-
<tbody>
|
|
168
|
-
<tr>
|
|
169
|
-
<td><strong>Default Delimiter</strong></td>
|
|
170
|
-
<td>Comma (<code>,</code>)</td>
|
|
171
|
-
</tr>
|
|
172
|
-
<tr>
|
|
173
|
-
<td><strong>Record Delimiter</strong></td>
|
|
174
|
-
<td>CRLF (<code>\r\n</code>) or LF (<code>\n</code>)</td>
|
|
175
|
-
</tr>
|
|
176
|
-
<tr>
|
|
177
|
-
<td><strong>Quote Character</strong></td>
|
|
178
|
-
<td>Double-quote (<code>"</code>)</td>
|
|
179
|
-
</tr>
|
|
180
|
-
<tr>
|
|
181
|
-
<td><strong>Quote Escaping</strong></td>
|
|
182
|
-
<td>Double quotes (<code>""</code>)</td>
|
|
183
|
-
</tr>
|
|
184
|
-
</tbody>
|
|
185
|
-
</table>
|
|
186
|
-
<h3>RFC 4180 Example</h3>
|
|
187
|
-
<pre class="prettyprint source lang-csv"><code>firstName,lastName,email
|
|
188
|
-
"Smith, John",Smith,john@example.com
|
|
189
|
-
Jane,Doe,jane@example.com
|
|
190
|
-
"Cooper, Andy",Cooper,andy@company.com
|
|
191
|
-
</code></pre>
|
|
192
|
-
<p>Note the quoted fields containing commas are properly handled. See <a href="RFC4180_MIGRATION_GUIDE.md">RFC4180_MIGRATION_GUIDE.md</a> for breaking changes and migration details.</p>
|
|
193
|
-
<h2>Quick Start</h2>
|
|
194
|
-
<h3>Installation</h3>
|
|
195
|
-
<pre class="prettyprint source lang-bash"><code>npm install convert-csv-to-json
|
|
196
|
-
</code></pre>
|
|
197
|
-
<h3>Synchronous (Simple)</h3>
|
|
198
|
-
<pre class="prettyprint source lang-js"><code>const csvToJson = require('convert-csv-to-json');
|
|
199
|
-
const json = csvToJson.getJsonFromCsv('input.csv');
|
|
200
|
-
</code></pre>
|
|
201
|
-
<h3>Asynchronous (Modern)</h3>
|
|
202
|
-
<pre class="prettyprint source lang-js"><code>const csvToJson = require('convert-csv-to-json');
|
|
203
|
-
const json = await csvToJson.getJsonFromCsvAsync('input.csv');
|
|
204
|
-
</code></pre>
|
|
205
|
-
<h3>Browser</h3>
|
|
206
|
-
<pre class="prettyprint source lang-js"><code>const convert = require('convert-csv-to-json');
|
|
207
|
-
const json = await convert.browser.parseFile(file);
|
|
208
|
-
</code></pre>
|
|
209
|
-
<h2>Documentation</h2>
|
|
210
|
-
<table>
|
|
211
|
-
<thead>
|
|
212
|
-
<tr>
|
|
213
|
-
<th>Implementation</th>
|
|
214
|
-
<th>Use Case</th>
|
|
215
|
-
<th>Learn More</th>
|
|
216
|
-
</tr>
|
|
217
|
-
</thead>
|
|
218
|
-
<tbody>
|
|
219
|
-
<tr>
|
|
220
|
-
<td><strong>Sync API</strong></td>
|
|
221
|
-
<td>Simple, blocking operations</td>
|
|
222
|
-
<td><a href="docs/SYNC.md">Read SYNC.md</a></td>
|
|
223
|
-
</tr>
|
|
224
|
-
<tr>
|
|
225
|
-
<td><strong>Async API</strong></td>
|
|
226
|
-
<td>Concurrent operations, large files</td>
|
|
227
|
-
<td><a href="docs/ASYNC.md">Read ASYNC.md</a></td>
|
|
228
|
-
</tr>
|
|
229
|
-
<tr>
|
|
230
|
-
<td><strong>Browser API</strong></td>
|
|
231
|
-
<td>Client-side file parsing</td>
|
|
232
|
-
<td><a href="docs/BROWSER.md">Read BROWSER.md</a></td>
|
|
233
|
-
</tr>
|
|
234
|
-
</tbody>
|
|
235
|
-
</table>
|
|
236
|
-
<h2>Common Tasks</h2>
|
|
237
|
-
<h3>Parse CSV String</h3>
|
|
238
|
-
<pre class="prettyprint source lang-js"><code>const json = csvToJson.csvStringToJson('name,age\nAlice,30');
|
|
239
|
-
</code></pre>
|
|
240
|
-
<h3>Custom Delimiter</h3>
|
|
241
|
-
<pre class="prettyprint source lang-js"><code>const json = csvToJson
|
|
242
|
-
.fieldDelimiter(';')
|
|
243
|
-
.getJsonFromCsv('input.csv');
|
|
244
|
-
</code></pre>
|
|
245
|
-
<h3>Format Values</h3>
|
|
246
|
-
<pre class="prettyprint source lang-js"><code>const json = csvToJson
|
|
247
|
-
.formatValueByType()
|
|
248
|
-
.getJsonFromCsv('input.csv');
|
|
249
|
-
// Converts "30" → 30, "true" → true, etc.
|
|
250
|
-
</code></pre>
|
|
251
|
-
<h3>Handle Quoted Fields</h3>
|
|
252
|
-
<pre class="prettyprint source lang-js"><code>const json = csvToJson
|
|
253
|
-
.supportQuotedField(true)
|
|
254
|
-
.getJsonFromCsv('input.csv');
|
|
255
|
-
</code></pre>
|
|
256
|
-
<h3>Batch Process Files (Async)</h3>
|
|
257
|
-
<pre class="prettyprint source lang-js"><code>const files = ['file1.csv', 'file2.csv', 'file3.csv'];
|
|
258
|
-
const results = await Promise.all(
|
|
259
|
-
files.map(f => csvToJson.getJsonFromCsvAsync(f))
|
|
260
|
-
);
|
|
261
|
-
</code></pre>
|
|
262
|
-
<h2>Configuration Options</h2>
|
|
263
|
-
<p>All APIs (Sync, Async and Browser) support the same configuration methods:</p>
|
|
264
|
-
<ul>
|
|
265
|
-
<li><code>fieldDelimiter(char)</code> - Set field delimiter (default: <code>,</code>)</li>
|
|
266
|
-
<li><code>formatValueByType()</code> - Auto-convert numbers, booleans</li>
|
|
267
|
-
<li><code>supportQuotedField(bool)</code> - Handle quoted fields with embedded delimiters</li>
|
|
268
|
-
<li><code>indexHeader(num)</code> - Specify header row (default: 0)</li>
|
|
269
|
-
<li><code>trimHeaderFieldWhiteSpace(bool)</code> - Remove spaces from headers</li>
|
|
270
|
-
<li><code>parseSubArray(delim, sep)</code> - Parse delimited arrays</li>
|
|
271
|
-
<li><code>mapRows(fn)</code> - Transform, filter, or enrich each row</li>
|
|
272
|
-
<li><code>utf8Encoding()</code>, <code>latin1Encoding()</code>, etc. - Set file encoding</li>
|
|
273
|
-
</ul>
|
|
274
|
-
<h3>Examples</h3>
|
|
275
|
-
<h4><code>fieldDelimiter(char)</code> - Set field delimiter (default: <code>,</code>)</h4>
|
|
276
|
-
<pre class="prettyprint source lang-js"><code>// Semicolon-delimited
|
|
277
|
-
csvToJson.fieldDelimiter(';').getJsonFromCsv('data.csv');
|
|
278
|
-
|
|
279
|
-
// Tab-delimited
|
|
280
|
-
csvToJson.fieldDelimiter('\t').getJsonFromCsv('data.tsv');
|
|
281
|
-
|
|
282
|
-
// Pipe-delimited
|
|
283
|
-
csvToJson.fieldDelimiter('|').getJsonFromCsv('data.psv');
|
|
284
|
-
</code></pre>
|
|
285
|
-
<h4><code>formatValueByType()</code> - Auto-convert numbers, booleans</h4>
|
|
286
|
-
<pre class="prettyprint source lang-js"><code>// Input: name,age,active
|
|
287
|
-
// John,30,true
|
|
288
|
-
csvToJson.formatValueByType().getJsonFromCsv('data.csv');
|
|
289
|
-
// Output: { name: 'John', age: 30, active: true }
|
|
290
|
-
</code></pre>
|
|
291
|
-
<h4><code>supportQuotedField(bool)</code> - Handle quoted fields with embedded delimiters</h4>
|
|
292
|
-
<pre class="prettyprint source lang-js"><code>// Input: name,description
|
|
293
|
-
// "Smith, John","He said ""Hello"""
|
|
294
|
-
csvToJson.supportQuotedField(true).getJsonFromCsv('data.csv');
|
|
295
|
-
// Output: { name: 'Smith, John', description: 'He said "Hello"' }
|
|
296
|
-
</code></pre>
|
|
297
|
-
<h4><code>indexHeader(num)</code> - Specify header row (default: 0)</h4>
|
|
298
|
-
<pre class="prettyprint source lang-js"><code>// If headers are in row 2 (3rd line):
|
|
299
|
-
csvToJson.indexHeader(2).getJsonFromCsv('data.csv');
|
|
300
|
-
</code></pre>
|
|
301
|
-
<h4><code>trimHeaderFieldWhiteSpace(bool)</code> - Remove spaces from headers</h4>
|
|
302
|
-
<pre class="prettyprint source lang-js"><code>// Input: " First Name ", " Last Name "
|
|
303
|
-
csvToJson.trimHeaderFieldWhiteSpace(true).getJsonFromCsv('data.csv');
|
|
304
|
-
// Output: { FirstName: 'John', LastName: 'Doe' }
|
|
305
|
-
</code></pre>
|
|
306
|
-
<h4><code>parseSubArray(delim, sep)</code> - Parse delimited arrays</h4>
|
|
307
|
-
<pre class="prettyprint source lang-js"><code>// Input: name,tags
|
|
308
|
-
// John,*javascript,nodejs,typescript*
|
|
309
|
-
csvToJson.parseSubArray('*', ',').getJsonFromCsv('data.csv');
|
|
310
|
-
// Output: { name: 'John', tags: ['javascript', 'nodejs', 'typescript'] }
|
|
311
|
-
</code></pre>
|
|
312
|
-
<h4><code>mapRows(fn)</code> - Transform, filter, or enrich each row</h4>
|
|
313
|
-
<pre class="prettyprint source lang-js"><code>// Filter out rows that don't match a condition
|
|
314
|
-
const result = csvToJson
|
|
315
|
-
.fieldDelimiter(',')
|
|
316
|
-
.mapRows((row) => {
|
|
317
|
-
// Only keep rows where age >= 30
|
|
318
|
-
if (parseInt(row.age) >= 30) {
|
|
319
|
-
return row;
|
|
320
|
-
}
|
|
321
|
-
return null; // Filters out this row
|
|
322
|
-
})
|
|
323
|
-
.getJsonFromCsv('input.csv');
|
|
324
|
-
</code></pre>
|
|
325
|
-
<p>See <a href="docs/MAPROWS.md">mapRows Feature - Usage Guide</a>.</p>
|
|
326
|
-
<h4><code>utf8Encoding()</code>, <code>latin1Encoding()</code>, etc. - Set file encoding</h4>
|
|
327
|
-
<pre class="prettyprint source lang-js"><code>// UTF-8 encoding
|
|
328
|
-
csvToJson.utf8Encoding().getJsonFromCsv('data.csv');
|
|
329
|
-
|
|
330
|
-
// Latin-1 encoding
|
|
331
|
-
csvToJson.latin1Encoding().getJsonFromCsv('data.csv');
|
|
332
|
-
|
|
333
|
-
// Custom encoding
|
|
334
|
-
csvToJson.customEncoding('ucs2').getJsonFromCsv('data.csv');
|
|
335
|
-
</code></pre>
|
|
336
|
-
<p>See <a href="docs/SYNC.md">SYNC.md</a>, <a href="docs/ASYNC.md">ASYNC.md</a> or <a href="docs/BROWSER.md">BROWSER.md</a> for complete configuration details.</p>
|
|
337
|
-
<h2>Example: Complete Workflow</h2>
|
|
338
|
-
<pre class="prettyprint source lang-js"><code>const csvToJson = require('convert-csv-to-json');
|
|
339
|
-
|
|
340
|
-
async function processCSV() {
|
|
341
|
-
const data = await csvToJson
|
|
342
|
-
.fieldDelimiter(',')
|
|
343
|
-
.formatValueByType()
|
|
344
|
-
.supportQuotedField(true)
|
|
345
|
-
.getJsonFromCsvAsync('data.csv');
|
|
346
|
-
|
|
347
|
-
console.log(`Parsed ${data.length} records`);
|
|
348
|
-
return data;
|
|
349
|
-
}
|
|
350
|
-
</code></pre>
|
|
351
|
-
<h2>Migration Guides</h2>
|
|
352
|
-
<ul>
|
|
353
|
-
<li><strong>RFC 4180 Breaking Changes</strong> - See <a href="migration/RFC4180_MIGRATION_GUIDE.md">RFC4180_MIGRATION_GUIDE.md</a></li>
|
|
354
|
-
<li><strong>Sync to Async Migration</strong> - See <a href="migration/MIGRATION_TO_ASYNC.md">MIGRATION.md</a></li>
|
|
355
|
-
<li><strong>Error Handling</strong> - See <a href="docs/ERROR_HANDLING.md">docs/ERROR_HANDLING.md</a> for comprehensive error documentation</li>
|
|
356
|
-
</ul>
|
|
357
|
-
<h2>Development</h2>
|
|
358
|
-
<p>Install dependencies:</p>
|
|
359
|
-
<pre class="prettyprint source lang-bash"><code>npm install
|
|
360
|
-
</code></pre>
|
|
361
|
-
<p>Run tests:</p>
|
|
362
|
-
<pre class="prettyprint source lang-bash"><code>npm test
|
|
363
|
-
</code></pre>
|
|
364
|
-
<p>Debug tests:</p>
|
|
365
|
-
<pre class="prettyprint source lang-bash"><code>npm run test-debug
|
|
366
|
-
</code></pre>
|
|
367
|
-
<h2>CI/CD GitHub Action</h2>
|
|
368
|
-
<p>See <a href=".github/workflows/ci-cd.yml">CI/CD GitHub Action</a>.</p>
|
|
369
|
-
<h3>Release</h3>
|
|
370
|
-
<p>When pushing to the <code>master</code> branch:</p>
|
|
371
|
-
<ul>
|
|
372
|
-
<li>Include <code>[MAJOR]</code> in commit message for major release (e.g., v1.0.0 → v2.0.0)</li>
|
|
373
|
-
<li>Include <code>[PATCH]</code> in commit message for patch release (e.g., v1.0.0 → v1.0.1)</li>
|
|
374
|
-
<li>Minor release is applied by default (e.g., v1.0.0 → v1.1.0)</li>
|
|
375
|
-
</ul>
|
|
376
|
-
<h2>License</h2>
|
|
377
|
-
<p>CSVtoJSON is licensed under the MIT <a href="LICENSE">License</a>.</p>
|
|
378
|
-
<hr>
|
|
379
|
-
<h2>Support</h2>
|
|
380
|
-
<p>Found a bug or need a feature? Open an issue on <a href="https://github.com/iuccio/csvToJson/issues">GitHub</a>.</p>
|
|
381
|
-
<p>Follow <a href="https://github.com/iuccio">me</a> and consider starring the project to show your support ⭐</p>
|
|
382
|
-
<h3>Buy Me a Coffee</h3>
|
|
383
|
-
<p>If you find this project helpful and would like to support its development:</p>
|
|
384
|
-
<p><strong>BTC</strong>: <code>37vdjQhbaR7k7XzhMKWzMcnqUxfw1njBNk</code></p></article>
|
|
385
|
-
</section>
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
</div>
|
|
393
|
-
|
|
394
|
-
<footer class="footer">
|
|
395
|
-
<div class="content has-text-centered">
|
|
396
|
-
<p>Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a></p>
|
|
397
|
-
<p class="sidebar-created-by">
|
|
398
|
-
<a href="https://github.com/SoftwareBrothers/better-docs" target="_blank">BetterDocs theme</a> provided with <i class="fas fa-heart"></i> by
|
|
399
|
-
<a href="http://softwarebrothers.co" target="_blank">SoftwareBrothers - JavaScript Development Agency</a>
|
|
400
|
-
</p>
|
|
401
|
-
</div>
|
|
402
|
-
</footer>
|
|
403
|
-
|
|
404
|
-
</div>
|
|
405
|
-
<div id="side-nav" class="side-nav">
|
|
406
|
-
</div>
|
|
407
|
-
</div>
|
|
408
|
-
<script src="scripts/app.min.js"></script>
|
|
409
|
-
<script>PR.prettyPrint();</script>
|
|
410
|
-
<script src="scripts/linenumber.js"> </script>
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
</body>
|
|
414
|
-
</html>
|