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
|
@@ -1,472 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
<!DOCTYPE html>
|
|
4
|
-
<html lang="en">
|
|
5
|
-
|
|
6
|
-
<head>
|
|
7
|
-
|
|
8
|
-
<meta charset="utf-8">
|
|
9
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
10
|
-
<title> src/util/errors.js</title>
|
|
11
|
-
|
|
12
|
-
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script>
|
|
13
|
-
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
|
|
14
|
-
<script src="./build/entry.js"></script>
|
|
15
|
-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
|
16
|
-
<!--[if lt IE 9]>
|
|
17
|
-
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
18
|
-
<![endif]-->
|
|
19
|
-
<link href="https://fonts.googleapis.com/css?family=Roboto:100,400,700|Inconsolata,700" rel="stylesheet">
|
|
20
|
-
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
|
|
21
|
-
<link type="text/css" rel="stylesheet" href="https://jmblog.github.io/color-themes-for-google-code-prettify/themes/tomorrow-night.min.css">
|
|
22
|
-
<link type="text/css" rel="stylesheet" href="styles/app.min.css">
|
|
23
|
-
<link type="text/css" rel="stylesheet" href="styles/iframe.css">
|
|
24
|
-
<link type="text/css" rel="stylesheet" href="./node_modules/better-docs/css/better-docs.css">
|
|
25
|
-
<script async defer src="https://buttons.github.io/buttons.js"></script>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
</head>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
<body class="layout small-header">
|
|
33
|
-
<div id="stickyNavbarOverlay"></div>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
<div class="top-nav">
|
|
37
|
-
<div class="inner">
|
|
38
|
-
<a id="hamburger" role="button" class="navbar-burger" aria-label="menu" aria-expanded="false">
|
|
39
|
-
<span aria-hidden="true"></span>
|
|
40
|
-
<span aria-hidden="true"></span>
|
|
41
|
-
<span aria-hidden="true"></span>
|
|
42
|
-
</a>
|
|
43
|
-
<div class="logo">
|
|
44
|
-
|
|
45
|
-
<a class="image" href="index.html">
|
|
46
|
-
<img src="https://raw.githubusercontent.com/iuccio/CSVtoJSON/master/CSVtoJSON.png" alt="logo">
|
|
47
|
-
</a>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
<a href="index.html">
|
|
51
|
-
<h1 class="navbar-item">Convert CSV to JSON</h1>
|
|
52
|
-
</a>
|
|
53
|
-
|
|
54
|
-
</div>
|
|
55
|
-
<div class="menu">
|
|
56
|
-
|
|
57
|
-
<div class="navigation">
|
|
58
|
-
<a
|
|
59
|
-
href="index.html"
|
|
60
|
-
class="link"
|
|
61
|
-
>
|
|
62
|
-
Documentation
|
|
63
|
-
</a>
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
<a
|
|
68
|
-
class="link user-link "
|
|
69
|
-
href="https://github.com/iuccio/CSVtoJSON"
|
|
70
|
-
>
|
|
71
|
-
GitHub
|
|
72
|
-
</a>
|
|
73
|
-
|
|
74
|
-
<a
|
|
75
|
-
class="link user-link "
|
|
76
|
-
href="https://www.npmjs.com/package/convert-csv-to-json"
|
|
77
|
-
>
|
|
78
|
-
NPM
|
|
79
|
-
</a>
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
</div>
|
|
84
|
-
</div>
|
|
85
|
-
</div>
|
|
86
|
-
</div>
|
|
87
|
-
<div id="main">
|
|
88
|
-
<div
|
|
89
|
-
class="sidebar "
|
|
90
|
-
id="sidebarNav"
|
|
91
|
-
>
|
|
92
|
-
|
|
93
|
-
<nav>
|
|
94
|
-
|
|
95
|
-
<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>
|
|
96
|
-
|
|
97
|
-
</nav>
|
|
98
|
-
</div>
|
|
99
|
-
<div class="core" id="main-content-wrapper">
|
|
100
|
-
<div class="content">
|
|
101
|
-
<header class="page-title">
|
|
102
|
-
<p>Source</p>
|
|
103
|
-
<h1>src/util/errors.js</h1>
|
|
104
|
-
</header>
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
<section>
|
|
111
|
-
<article>
|
|
112
|
-
<pre class="prettyprint source linenums"><code>'use strict';
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Custom error classes following clean code principles
|
|
116
|
-
* Provides clear, actionable error messages with context
|
|
117
|
-
* @category Error Classes
|
|
118
|
-
*/
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Base class for all CSV parsing errors
|
|
122
|
-
* Provides consistent error formatting and context
|
|
123
|
-
* @category Error Classes
|
|
124
|
-
*/
|
|
125
|
-
class CsvParsingError extends Error {
|
|
126
|
-
/**
|
|
127
|
-
* Create a CSV parsing error
|
|
128
|
-
* @param {string} message - Error message
|
|
129
|
-
* @param {string} code - Error code for identification
|
|
130
|
-
* @param {object} context - Additional context information (default: {})
|
|
131
|
-
*/
|
|
132
|
-
constructor(message, code, context = {}) {
|
|
133
|
-
super(message);
|
|
134
|
-
this.name = 'CsvParsingError';
|
|
135
|
-
this.code = code;
|
|
136
|
-
this.context = context;
|
|
137
|
-
Error.captureStackTrace(this, this.constructor);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Convert error to formatted string with context information
|
|
142
|
-
* @returns {string} Formatted error message including context
|
|
143
|
-
*/
|
|
144
|
-
toString() {
|
|
145
|
-
let output = `${this.name}: ${this.message}`;
|
|
146
|
-
|
|
147
|
-
if (this.context && Object.keys(this.context).length > 0) {
|
|
148
|
-
output += '\n\nContext:';
|
|
149
|
-
Object.entries(this.context).forEach(([key, value]) => {
|
|
150
|
-
output += `\n ${key}: ${this.formatValue(value)}`;
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return output;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Format a context value for display in error message
|
|
159
|
-
* @param {unknown} value - Value to format
|
|
160
|
-
* @returns {string} Formatted value string
|
|
161
|
-
* @private
|
|
162
|
-
*/
|
|
163
|
-
formatValue(value) {
|
|
164
|
-
if (value === null) return 'null';
|
|
165
|
-
if (value === undefined) return 'undefined';
|
|
166
|
-
if (typeof value === 'string') return `"${value}"`;
|
|
167
|
-
if (typeof value === 'object') return JSON.stringify(value);
|
|
168
|
-
return String(value);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Input validation errors
|
|
174
|
-
* Thrown when function parameters don't meet expected type or value requirements
|
|
175
|
-
* @category Error Classes
|
|
176
|
-
*/
|
|
177
|
-
class InputValidationError extends CsvParsingError {
|
|
178
|
-
/**
|
|
179
|
-
* Create an input validation error
|
|
180
|
-
* @param {string} paramName - Name of the invalid parameter
|
|
181
|
-
* @param {string} expectedType - Expected type description
|
|
182
|
-
* @param {string} receivedType - Actual type received
|
|
183
|
-
* @param {string} details - Additional error details (optional)
|
|
184
|
-
*/
|
|
185
|
-
constructor(paramName, expectedType, receivedType, details = '') {
|
|
186
|
-
const message =
|
|
187
|
-
`Invalid input: Parameter '${paramName}' is required.\n` +
|
|
188
|
-
`Expected: ${expectedType}\n` +
|
|
189
|
-
`Received: ${receivedType}${details ? '\n' + details : ''}`;
|
|
190
|
-
|
|
191
|
-
super(message, 'INPUT_VALIDATION_ERROR', {
|
|
192
|
-
parameter: paramName,
|
|
193
|
-
expectedType,
|
|
194
|
-
receivedType
|
|
195
|
-
});
|
|
196
|
-
this.name = 'InputValidationError';
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Configuration-related errors
|
|
202
|
-
* Thrown when configuration options conflict or are invalid
|
|
203
|
-
* @category Error Classes
|
|
204
|
-
*/
|
|
205
|
-
class ConfigurationError extends CsvParsingError {
|
|
206
|
-
/**
|
|
207
|
-
* Create a configuration error
|
|
208
|
-
* @param {string} message - Error message
|
|
209
|
-
* @param {object} conflictingOptions - Configuration options in conflict (optional)
|
|
210
|
-
*/
|
|
211
|
-
constructor(message, conflictingOptions = {}) {
|
|
212
|
-
super(message, 'CONFIGURATION_ERROR', conflictingOptions);
|
|
213
|
-
this.name = 'ConfigurationError';
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Create error for quoted field configuration conflict
|
|
218
|
-
* Occurs when quote character is used as delimiter while quoted fields are enabled
|
|
219
|
-
* @param {string} optionName - Name of the conflicting option
|
|
220
|
-
* @param {string} value - Value that causes the conflict
|
|
221
|
-
* @returns {ConfigurationError} Configured error instance
|
|
222
|
-
* @static
|
|
223
|
-
*/
|
|
224
|
-
static quotedFieldConflict(optionName, value) {
|
|
225
|
-
return new ConfigurationError(
|
|
226
|
-
`Configuration conflict: supportQuotedField() is enabled, but ${optionName} is set to '${value}'.\n` +
|
|
227
|
-
`The quote character (") cannot be used as a field delimiter, separator, or sub-array delimiter when quoted field support is active.\n\n` +
|
|
228
|
-
`Solutions:\n` +
|
|
229
|
-
` 1. Use a different character for ${optionName} (e.g., '|', '\\t', ';')\n` +
|
|
230
|
-
` 2. Disable supportQuotedField() if your CSV doesn't contain quoted fields\n` +
|
|
231
|
-
` 3. Refer to RFC 4180 for proper CSV formatting: https://tools.ietf.org/html/rfc4180`,
|
|
232
|
-
{ optionName, value, conflictingOption: 'supportQuotedField' }
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Create error for invalid header index
|
|
238
|
-
* Occurs when indexHeader() receives non-numeric value
|
|
239
|
-
* @param {unknown} value - Invalid header index value
|
|
240
|
-
* @returns {ConfigurationError} Configured error instance
|
|
241
|
-
* @static
|
|
242
|
-
*/
|
|
243
|
-
static invalidHeaderIndex(value) {
|
|
244
|
-
return new ConfigurationError(
|
|
245
|
-
`Invalid configuration: indexHeader() expects a numeric value.\n` +
|
|
246
|
-
`Received: ${typeof value} (${value})\n\n` +
|
|
247
|
-
`Solutions:\n` +
|
|
248
|
-
` 1. Ensure indexHeader() receives a number: indexHeader(0), indexHeader(1), etc.\n` +
|
|
249
|
-
` 2. Headers are typically found on row 0 (first line)\n` +
|
|
250
|
-
` 3. Use indexHeader(2) if headers are on the 3rd line`,
|
|
251
|
-
{ parameterName: 'indexHeader', value, type: typeof value }
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* CSV parsing errors with detailed context
|
|
258
|
-
* Thrown when CSV format is invalid or malformed
|
|
259
|
-
* @category Error Classes
|
|
260
|
-
*/
|
|
261
|
-
class CsvFormatError extends CsvParsingError {
|
|
262
|
-
/**
|
|
263
|
-
* Create a CSV format error
|
|
264
|
-
* @param {string} message - Error message
|
|
265
|
-
* @param {object} context - Additional context information (optional)
|
|
266
|
-
*/
|
|
267
|
-
constructor(message, context = {}) {
|
|
268
|
-
super(message, 'CSV_FORMAT_ERROR', context);
|
|
269
|
-
this.name = 'CsvFormatError';
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Create error for missing CSV header row
|
|
274
|
-
* Occurs when no valid header row is found in CSV
|
|
275
|
-
* @returns {CsvFormatError} Configured error instance
|
|
276
|
-
* @static
|
|
277
|
-
*/
|
|
278
|
-
static missingHeader() {
|
|
279
|
-
return new CsvFormatError(
|
|
280
|
-
`CSV parsing error: No header row found.\n` +
|
|
281
|
-
`The CSV file appears to be empty or has no valid header line.\n\n` +
|
|
282
|
-
`Solutions:\n` +
|
|
283
|
-
` 1. Ensure your CSV file contains at least one row (header row)\n` +
|
|
284
|
-
` 2. Verify the file is not empty or contains only whitespace\n` +
|
|
285
|
-
` 3. Check if you need to use indexHeader(n) to specify a non-standard header row\n` +
|
|
286
|
-
` 4. Refer to RFC 4180 for proper CSV format: https://tools.ietf.org/html/rfc4180`
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Create error for mismatched quotes in CSV
|
|
292
|
-
* Occurs when quoted fields are not properly closed
|
|
293
|
-
* @param {string} location - Where the error occurred (default: 'CSV')
|
|
294
|
-
* @returns {CsvFormatError} Configured error instance
|
|
295
|
-
* @static
|
|
296
|
-
*/
|
|
297
|
-
static mismatchedQuotes(location = 'CSV') {
|
|
298
|
-
return new CsvFormatError(
|
|
299
|
-
`CSV parsing error: Mismatched quotes detected in ${location}.\n` +
|
|
300
|
-
`A quoted field was not properly closed with a matching quote character.\n\n` +
|
|
301
|
-
`RFC 4180 rules for quoted fields:\n` +
|
|
302
|
-
` • Fields containing delimiters or quotes MUST be enclosed in double quotes\n` +
|
|
303
|
-
` • To include a quote within a quoted field, use two consecutive quotes: ""\n` +
|
|
304
|
-
` • Example: "Smith, John" (name contains comma)\n` +
|
|
305
|
-
` • Example: "He said ""Hello""" (text contains quotes)\n\n` +
|
|
306
|
-
`Solutions:\n` +
|
|
307
|
-
` 1. Review your CSV for properly paired quote characters\n` +
|
|
308
|
-
` 2. Use double quotes ("") to escape quotes within quoted fields\n` +
|
|
309
|
-
` 3. Ensure all commas within field values are inside quotes\n` +
|
|
310
|
-
` 4. Enable supportQuotedField(true) if you're using quoted fields`,
|
|
311
|
-
{ location }
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* File operation errors
|
|
318
|
-
* Thrown when file read or write operations fail
|
|
319
|
-
* @category Error Classes
|
|
320
|
-
*/
|
|
321
|
-
class FileOperationError extends CsvParsingError {
|
|
322
|
-
/**
|
|
323
|
-
* Create a file operation error
|
|
324
|
-
* @param {string} operation - Type of operation that failed (e.g., 'read', 'write')
|
|
325
|
-
* @param {string} filePath - Path to the file where operation failed
|
|
326
|
-
* @param {Error} originalError - The underlying error object from Node.js
|
|
327
|
-
*/
|
|
328
|
-
constructor(operation, filePath, originalError) {
|
|
329
|
-
const message =
|
|
330
|
-
`File operation error: Failed to ${operation} file.\n` +
|
|
331
|
-
`File path: ${filePath}\n` +
|
|
332
|
-
`Reason: ${originalError.message}\n\n` +
|
|
333
|
-
`Solutions:\n` +
|
|
334
|
-
` 1. Verify the file path is correct: ${filePath}\n` +
|
|
335
|
-
` 2. Check file permissions (read access for input, write access for output)\n` +
|
|
336
|
-
` 3. Ensure the directory exists and is writable for output files\n` +
|
|
337
|
-
` 4. Verify the file is not in use by another process`;
|
|
338
|
-
|
|
339
|
-
super(message, 'FILE_OPERATION_ERROR', {
|
|
340
|
-
operation,
|
|
341
|
-
filePath,
|
|
342
|
-
originalError: originalError.message
|
|
343
|
-
});
|
|
344
|
-
this.name = 'FileOperationError';
|
|
345
|
-
this.originalError = originalError;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* JSON validation errors
|
|
351
|
-
* Thrown when parsed CSV data cannot be converted to valid JSON
|
|
352
|
-
* @category Error Classes
|
|
353
|
-
*/
|
|
354
|
-
class JsonValidationError extends CsvParsingError {
|
|
355
|
-
/**
|
|
356
|
-
* Create a JSON validation error
|
|
357
|
-
* @param {string} csvData - The CSV data that failed validation
|
|
358
|
-
* @param {Error} originalError - The underlying JSON parsing error
|
|
359
|
-
*/
|
|
360
|
-
constructor(csvData, originalError) {
|
|
361
|
-
const message =
|
|
362
|
-
`JSON validation error: The parsed CSV data generated invalid JSON.\n` +
|
|
363
|
-
`This typically indicates malformed field names or values in the CSV.\n` +
|
|
364
|
-
`Original error: ${originalError.message}\n\n` +
|
|
365
|
-
`Solutions:\n` +
|
|
366
|
-
` 1. Check that field names are valid JavaScript identifiers (or will be converted safely)\n` +
|
|
367
|
-
` 2. Review the CSV data for special characters that aren't properly escaped\n` +
|
|
368
|
-
` 3. Enable supportQuotedField(true) for fields containing special characters\n` +
|
|
369
|
-
` 4. Verify that formatValueByType() isn't converting values incorrectly`;
|
|
370
|
-
|
|
371
|
-
super(message, 'JSON_VALIDATION_ERROR', {
|
|
372
|
-
originalError: originalError.message,
|
|
373
|
-
csvPreview: csvData ? csvData.substring(0, 200) : 'N/A'
|
|
374
|
-
});
|
|
375
|
-
this.name = 'JsonValidationError';
|
|
376
|
-
this.originalError = originalError;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Browser-specific errors
|
|
382
|
-
* Thrown when browser API operations fail
|
|
383
|
-
* @category Error Classes
|
|
384
|
-
*/
|
|
385
|
-
class BrowserApiError extends CsvParsingError {
|
|
386
|
-
/**
|
|
387
|
-
* Create a browser API error
|
|
388
|
-
* @param {string} message - Error message
|
|
389
|
-
* @param {object} context - Additional context information (optional)
|
|
390
|
-
*/
|
|
391
|
-
constructor(message, context = {}) {
|
|
392
|
-
super(message, 'BROWSER_API_ERROR', context);
|
|
393
|
-
this.name = 'BrowserApiError';
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* Create error for unavailable FileReader API
|
|
398
|
-
* Occurs when browser doesn't support FileReader
|
|
399
|
-
* @returns {BrowserApiError} Configured error instance
|
|
400
|
-
* @static
|
|
401
|
-
*/
|
|
402
|
-
static fileReaderNotAvailable() {
|
|
403
|
-
return new BrowserApiError(
|
|
404
|
-
`Browser compatibility error: FileReader API is not available.\n` +
|
|
405
|
-
`Your browser does not support the FileReader API required for file parsing.\n\n` +
|
|
406
|
-
`Solutions:\n` +
|
|
407
|
-
` 1. Use a modern browser that supports FileReader (Chrome 13+, Firefox 10+, Safari 6+)\n` +
|
|
408
|
-
` 2. Consider using csvStringToJson() or csvStringToJsonAsync() for string-based parsing\n` +
|
|
409
|
-
` 3. Implement a polyfill or alternative file reading method`
|
|
410
|
-
);
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* Create error for file parsing failure in browser
|
|
415
|
-
* Occurs when file read or CSV parse fails
|
|
416
|
-
* @param {Error} originalError - The underlying error that occurred
|
|
417
|
-
* @returns {BrowserApiError} Configured error instance
|
|
418
|
-
* @static
|
|
419
|
-
*/
|
|
420
|
-
static parseFileError(originalError) {
|
|
421
|
-
return new BrowserApiError(
|
|
422
|
-
`Browser file parsing error: Failed to read and parse the file.\n` +
|
|
423
|
-
`Error details: ${originalError.message}\n\n` +
|
|
424
|
-
`Solutions:\n` +
|
|
425
|
-
` 1. Verify the file is a valid CSV file\n` +
|
|
426
|
-
` 2. Check the file encoding (UTF-8 is recommended)\n` +
|
|
427
|
-
` 3. Try a smaller file to isolate the issue\n` +
|
|
428
|
-
` 4. Check browser console for additional error details`,
|
|
429
|
-
{ originalError: originalError.message }
|
|
430
|
-
);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
module.exports = {
|
|
435
|
-
CsvParsingError,
|
|
436
|
-
InputValidationError,
|
|
437
|
-
ConfigurationError,
|
|
438
|
-
CsvFormatError,
|
|
439
|
-
FileOperationError,
|
|
440
|
-
JsonValidationError,
|
|
441
|
-
BrowserApiError
|
|
442
|
-
};
|
|
443
|
-
</code></pre>
|
|
444
|
-
</article>
|
|
445
|
-
</section>
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
</div>
|
|
451
|
-
|
|
452
|
-
<footer class="footer">
|
|
453
|
-
<div class="content has-text-centered">
|
|
454
|
-
<p>Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a></p>
|
|
455
|
-
<p class="sidebar-created-by">
|
|
456
|
-
<a href="https://github.com/SoftwareBrothers/better-docs" target="_blank">BetterDocs theme</a> provided with <i class="fas fa-heart"></i> by
|
|
457
|
-
<a href="http://softwarebrothers.co" target="_blank">SoftwareBrothers - JavaScript Development Agency</a>
|
|
458
|
-
</p>
|
|
459
|
-
</div>
|
|
460
|
-
</footer>
|
|
461
|
-
|
|
462
|
-
</div>
|
|
463
|
-
<div id="side-nav" class="side-nav">
|
|
464
|
-
</div>
|
|
465
|
-
</div>
|
|
466
|
-
<script src="scripts/app.min.js"></script>
|
|
467
|
-
<script>PR.prettyPrint();</script>
|
|
468
|
-
<script src="scripts/linenumber.js"> </script>
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
</body>
|
|
472
|
-
</html>
|