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,238 +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/fileUtils.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/fileUtils.js</h1>
|
|
104
|
-
</header>
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
<section>
|
|
111
|
-
<article>
|
|
112
|
-
<pre class="prettyprint source linenums"><code>'use strict';
|
|
113
|
-
|
|
114
|
-
const fs = require('fs');
|
|
115
|
-
const { FileOperationError } = require('./errors');
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* File I/O utilities for reading and writing CSV/JSON files
|
|
119
|
-
* Provides both synchronous and asynchronous file operations
|
|
120
|
-
* @category Utilities
|
|
121
|
-
*/
|
|
122
|
-
class FileUtils {
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Read a file synchronously with specified encoding
|
|
126
|
-
* @param {string} fileInputName - Path to file to read
|
|
127
|
-
* @param {string} encoding - File encoding (e.g., 'utf8', 'latin1')
|
|
128
|
-
* @returns {string} File contents as string
|
|
129
|
-
* @throws {FileOperationError} If file read fails
|
|
130
|
-
*/
|
|
131
|
-
readFile(fileInputName, encoding) {
|
|
132
|
-
try {
|
|
133
|
-
return fs.readFileSync(fileInputName, encoding).toString();
|
|
134
|
-
} catch (error) {
|
|
135
|
-
throw new FileOperationError('read', fileInputName, error);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Read a file asynchronously with specified encoding
|
|
141
|
-
* Uses fs.promises when available, falls back to callback-based API
|
|
142
|
-
* @param {string} fileInputName - Path to file to read
|
|
143
|
-
* @param {string} encoding - File encoding (default: 'utf8')
|
|
144
|
-
* @returns {Promise<string>} Promise resolving to file contents
|
|
145
|
-
* @throws {FileOperationError} If file read fails
|
|
146
|
-
*/
|
|
147
|
-
readFileAsync(fileInputName, encoding = 'utf8') {
|
|
148
|
-
// Use fs.promises when available for a Promise-based API
|
|
149
|
-
if (fs.promises && typeof fs.promises.readFile === 'function') {
|
|
150
|
-
return fs.promises.readFile(fileInputName, encoding)
|
|
151
|
-
.then(buf => buf.toString())
|
|
152
|
-
.catch(error => {
|
|
153
|
-
throw new FileOperationError('read', fileInputName, error);
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
return new Promise((resolve, reject) => {
|
|
157
|
-
fs.readFile(fileInputName, encoding, (err, data) => {
|
|
158
|
-
if (err) {
|
|
159
|
-
reject(new FileOperationError('read', fileInputName, err));
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
resolve(data.toString());
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Write content to a file synchronously
|
|
169
|
-
* Logs confirmation message to console on success
|
|
170
|
-
* @param {string} json - Content to write to file
|
|
171
|
-
* @param {string} fileOutputName - Path to output file
|
|
172
|
-
* @throws {FileOperationError} If file write fails
|
|
173
|
-
*/
|
|
174
|
-
writeFile(json, fileOutputName) {
|
|
175
|
-
fs.writeFile(fileOutputName, json, function (err) {
|
|
176
|
-
if (err) {
|
|
177
|
-
throw new FileOperationError('write', fileOutputName, err);
|
|
178
|
-
} else {
|
|
179
|
-
console.log('File saved: ' + fileOutputName);
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Write content to a file asynchronously
|
|
186
|
-
* Uses fs.promises when available, falls back to callback-based API
|
|
187
|
-
* @param {string} json - Content to write to file
|
|
188
|
-
* @param {string} fileOutputName - Path to output file
|
|
189
|
-
* @returns {Promise<void>} Promise that resolves when write completes
|
|
190
|
-
* @throws {FileOperationError} If file write fails
|
|
191
|
-
*/
|
|
192
|
-
writeFileAsync(json, fileOutputName) {
|
|
193
|
-
if (fs.promises && typeof fs.promises.writeFile === 'function') {
|
|
194
|
-
return fs.promises.writeFile(fileOutputName, json)
|
|
195
|
-
.catch(error => {
|
|
196
|
-
throw new FileOperationError('write', fileOutputName, error);
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
return new Promise((resolve, reject) => {
|
|
200
|
-
fs.writeFile(fileOutputName, json, (err) => {
|
|
201
|
-
if (err) return reject(new FileOperationError('write', fileOutputName, err));
|
|
202
|
-
resolve();
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
module.exports = new FileUtils();
|
|
209
|
-
</code></pre>
|
|
210
|
-
</article>
|
|
211
|
-
</section>
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
</div>
|
|
217
|
-
|
|
218
|
-
<footer class="footer">
|
|
219
|
-
<div class="content has-text-centered">
|
|
220
|
-
<p>Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a></p>
|
|
221
|
-
<p class="sidebar-created-by">
|
|
222
|
-
<a href="https://github.com/SoftwareBrothers/better-docs" target="_blank">BetterDocs theme</a> provided with <i class="fas fa-heart"></i> by
|
|
223
|
-
<a href="http://softwarebrothers.co" target="_blank">SoftwareBrothers - JavaScript Development Agency</a>
|
|
224
|
-
</p>
|
|
225
|
-
</div>
|
|
226
|
-
</footer>
|
|
227
|
-
|
|
228
|
-
</div>
|
|
229
|
-
<div id="side-nav" class="side-nav">
|
|
230
|
-
</div>
|
|
231
|
-
</div>
|
|
232
|
-
<script src="scripts/app.min.js"></script>
|
|
233
|
-
<script>PR.prettyPrint();</script>
|
|
234
|
-
<script src="scripts/linenumber.js"> </script>
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
</body>
|
|
238
|
-
</html>
|
|
@@ -1,166 +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/jsonUtils.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/jsonUtils.js</h1>
|
|
104
|
-
</header>
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
<section>
|
|
111
|
-
<article>
|
|
112
|
-
<pre class="prettyprint source linenums"><code>'use strict';
|
|
113
|
-
|
|
114
|
-
const { JsonValidationError } = require('./errors');
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* JSON validation utilities
|
|
118
|
-
* @category Utilities
|
|
119
|
-
*/
|
|
120
|
-
class JsonUtil {
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Validate that a string is valid JSON
|
|
124
|
-
* @param {string} json - JSON string to validate
|
|
125
|
-
* @throws {JsonValidationError} If JSON is invalid
|
|
126
|
-
*/
|
|
127
|
-
validateJson(json) {
|
|
128
|
-
try {
|
|
129
|
-
JSON.parse(json);
|
|
130
|
-
} catch (err) {
|
|
131
|
-
throw new JsonValidationError(json, err);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
module.exports = new JsonUtil();</code></pre>
|
|
138
|
-
</article>
|
|
139
|
-
</section>
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
</div>
|
|
145
|
-
|
|
146
|
-
<footer class="footer">
|
|
147
|
-
<div class="content has-text-centered">
|
|
148
|
-
<p>Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a></p>
|
|
149
|
-
<p class="sidebar-created-by">
|
|
150
|
-
<a href="https://github.com/SoftwareBrothers/better-docs" target="_blank">BetterDocs theme</a> provided with <i class="fas fa-heart"></i> by
|
|
151
|
-
<a href="http://softwarebrothers.co" target="_blank">SoftwareBrothers - JavaScript Development Agency</a>
|
|
152
|
-
</p>
|
|
153
|
-
</div>
|
|
154
|
-
</footer>
|
|
155
|
-
|
|
156
|
-
</div>
|
|
157
|
-
<div id="side-nav" class="side-nav">
|
|
158
|
-
</div>
|
|
159
|
-
</div>
|
|
160
|
-
<script src="scripts/app.min.js"></script>
|
|
161
|
-
<script>PR.prettyPrint();</script>
|
|
162
|
-
<script src="scripts/linenumber.js"> </script>
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
</body>
|
|
166
|
-
</html>
|