convert-csv-to-json 4.2.0 → 4.3.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/.eslintignore +3 -0
- package/.eslintrc.json +48 -0
- package/.github/workflows/ci-cd.yml +28 -2
- package/docs/api/BrowserApi.html +2435 -0
- package/docs/api/BrowserApiError.html +522 -0
- package/docs/api/ConfigurationError.html +594 -0
- package/docs/api/CsvFormatError.html +530 -0
- package/docs/api/CsvParsingError.html +384 -0
- package/docs/api/CsvToJson.html +3136 -0
- package/docs/api/CsvToJsonAsync.html +2672 -0
- package/docs/api/FileOperationError.html +270 -0
- package/docs/api/FileUtils.html +1012 -0
- package/docs/api/InputValidationError.html +293 -0
- package/docs/api/JsonUtil.html +340 -0
- package/docs/api/JsonValidationError.html +247 -0
- package/docs/api/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docs/api/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/docs/api/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docs/api/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docs/api/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/docs/api/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docs/api/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docs/api/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/docs/api/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docs/api/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docs/api/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/docs/api/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docs/api/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docs/api/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/docs/api/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docs/api/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docs/api/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/docs/api/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docs/api/global.html +3315 -0
- package/docs/api/index.html +326 -0
- package/docs/api/index.js.html +341 -0
- package/docs/api/scripts/linenumber.js +25 -0
- package/docs/api/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/api/scripts/prettify/lang-css.js +2 -0
- package/docs/api/scripts/prettify/prettify.js +28 -0
- package/docs/api/src_browserApi.js.html +271 -0
- package/docs/api/src_csvToJson.js.html +605 -0
- package/docs/api/src_csvToJsonAsync.js.html +244 -0
- package/docs/api/src_util_errors.js.html +374 -0
- package/docs/api/src_util_fileUtils.js.html +147 -0
- package/docs/api/src_util_jsonUtils.js.html +75 -0
- package/docs/api/src_util_stringUtils.js.html +212 -0
- package/docs/api/styles/jsdoc-default.css +358 -0
- package/docs/api/styles/prettify-jsdoc.css +111 -0
- package/docs/api/styles/prettify-tomorrow.css +132 -0
- package/index.js +109 -32
- package/jsdoc.json +17 -0
- package/package.json +10 -3
- package/src/browserApi.js +96 -4
- package/src/csvToJson.js +163 -2
- package/src/csvToJsonAsync.js +74 -14
- package/src/util/errors.js +96 -0
- package/src/util/fileUtils.js +34 -0
- package/src/util/jsonUtils.js +8 -0
- package/src/util/stringUtils.js +51 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>JSDoc: Source: src/util/fileUtils.js</title>
|
|
6
|
+
|
|
7
|
+
<script src="scripts/prettify/prettify.js"> </script>
|
|
8
|
+
<script src="scripts/prettify/lang-css.js"> </script>
|
|
9
|
+
<!--[if lt IE 9]>
|
|
10
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
11
|
+
<![endif]-->
|
|
12
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
13
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
14
|
+
</head>
|
|
15
|
+
|
|
16
|
+
<body>
|
|
17
|
+
|
|
18
|
+
<div id="main">
|
|
19
|
+
|
|
20
|
+
<h1 class="page-title">Source: src/util/fileUtils.js</h1>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
<section>
|
|
28
|
+
<article>
|
|
29
|
+
<pre class="prettyprint source linenums"><code>'use strict';
|
|
30
|
+
|
|
31
|
+
const fs = require('fs');
|
|
32
|
+
const { FileOperationError } = require('./errors');
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* File I/O utilities for reading and writing CSV/JSON files
|
|
36
|
+
* Provides both synchronous and asynchronous file operations
|
|
37
|
+
*/
|
|
38
|
+
class FileUtils {
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Read a file synchronously with specified encoding
|
|
42
|
+
* @param {string} fileInputName - Path to file to read
|
|
43
|
+
* @param {string} encoding - File encoding (e.g., 'utf8', 'latin1')
|
|
44
|
+
* @returns {string} File contents as string
|
|
45
|
+
* @throws {FileOperationError} If file read fails
|
|
46
|
+
*/
|
|
47
|
+
readFile(fileInputName, encoding) {
|
|
48
|
+
try {
|
|
49
|
+
return fs.readFileSync(fileInputName, encoding).toString();
|
|
50
|
+
} catch (error) {
|
|
51
|
+
throw new FileOperationError('read', fileInputName, error);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Read a file asynchronously with specified encoding
|
|
57
|
+
* Uses fs.promises when available, falls back to callback-based API
|
|
58
|
+
* @param {string} fileInputName - Path to file to read
|
|
59
|
+
* @param {string} encoding - File encoding (default: 'utf8')
|
|
60
|
+
* @returns {Promise<string>} Promise resolving to file contents
|
|
61
|
+
* @throws {FileOperationError} If file read fails
|
|
62
|
+
*/
|
|
63
|
+
readFileAsync(fileInputName, encoding = 'utf8') {
|
|
64
|
+
// Use fs.promises when available for a Promise-based API
|
|
65
|
+
if (fs.promises && typeof fs.promises.readFile === 'function') {
|
|
66
|
+
return fs.promises.readFile(fileInputName, encoding)
|
|
67
|
+
.then(buf => buf.toString())
|
|
68
|
+
.catch(error => {
|
|
69
|
+
throw new FileOperationError('read', fileInputName, error);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
fs.readFile(fileInputName, encoding, (err, data) => {
|
|
74
|
+
if (err) {
|
|
75
|
+
reject(new FileOperationError('read', fileInputName, err));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
resolve(data.toString());
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Write content to a file synchronously
|
|
85
|
+
* Logs confirmation message to console on success
|
|
86
|
+
* @param {string} json - Content to write to file
|
|
87
|
+
* @param {string} fileOutputName - Path to output file
|
|
88
|
+
* @throws {FileOperationError} If file write fails
|
|
89
|
+
*/
|
|
90
|
+
writeFile(json, fileOutputName) {
|
|
91
|
+
fs.writeFile(fileOutputName, json, function (err) {
|
|
92
|
+
if (err) {
|
|
93
|
+
throw new FileOperationError('write', fileOutputName, err);
|
|
94
|
+
} else {
|
|
95
|
+
console.log('File saved: ' + fileOutputName);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Write content to a file asynchronously
|
|
102
|
+
* Uses fs.promises when available, falls back to callback-based API
|
|
103
|
+
* @param {string} json - Content to write to file
|
|
104
|
+
* @param {string} fileOutputName - Path to output file
|
|
105
|
+
* @returns {Promise<void>} Promise that resolves when write completes
|
|
106
|
+
* @throws {FileOperationError} If file write fails
|
|
107
|
+
*/
|
|
108
|
+
writeFileAsync(json, fileOutputName) {
|
|
109
|
+
if (fs.promises && typeof fs.promises.writeFile === 'function') {
|
|
110
|
+
return fs.promises.writeFile(fileOutputName, json)
|
|
111
|
+
.catch(error => {
|
|
112
|
+
throw new FileOperationError('write', fileOutputName, error);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return new Promise((resolve, reject) => {
|
|
116
|
+
fs.writeFile(fileOutputName, json, (err) => {
|
|
117
|
+
if (err) return reject(new FileOperationError('write', fileOutputName, err));
|
|
118
|
+
resolve();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
}
|
|
124
|
+
module.exports = new FileUtils();
|
|
125
|
+
</code></pre>
|
|
126
|
+
</article>
|
|
127
|
+
</section>
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
</div>
|
|
133
|
+
|
|
134
|
+
<nav>
|
|
135
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="BrowserApi.html">BrowserApi</a></li><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="CsvToJson.html">CsvToJson</a></li><li><a href="CsvToJsonAsync.html">CsvToJsonAsync</a></li><li><a href="FileOperationError.html">FileOperationError</a></li><li><a href="FileUtils.html">FileUtils</a></li><li><a href="InputValidationError.html">InputValidationError</a></li><li><a href="JsonUtil.html">JsonUtil</a></li><li><a href="JsonValidationError.html">JsonValidationError</a></li></ul><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#browser">browser</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>
|
|
136
|
+
</nav>
|
|
137
|
+
|
|
138
|
+
<br class="clear">
|
|
139
|
+
|
|
140
|
+
<footer>
|
|
141
|
+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.5</a> on Fri Mar 20 2026 14:48:29 GMT+0000 (Coordinated Universal Time)
|
|
142
|
+
</footer>
|
|
143
|
+
|
|
144
|
+
<script> prettyPrint(); </script>
|
|
145
|
+
<script src="scripts/linenumber.js"> </script>
|
|
146
|
+
</body>
|
|
147
|
+
</html>
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>JSDoc: Source: src/util/jsonUtils.js</title>
|
|
6
|
+
|
|
7
|
+
<script src="scripts/prettify/prettify.js"> </script>
|
|
8
|
+
<script src="scripts/prettify/lang-css.js"> </script>
|
|
9
|
+
<!--[if lt IE 9]>
|
|
10
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
11
|
+
<![endif]-->
|
|
12
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
13
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
14
|
+
</head>
|
|
15
|
+
|
|
16
|
+
<body>
|
|
17
|
+
|
|
18
|
+
<div id="main">
|
|
19
|
+
|
|
20
|
+
<h1 class="page-title">Source: src/util/jsonUtils.js</h1>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
<section>
|
|
28
|
+
<article>
|
|
29
|
+
<pre class="prettyprint source linenums"><code>'use strict';
|
|
30
|
+
|
|
31
|
+
const { JsonValidationError } = require('./errors');
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* JSON validation utilities
|
|
35
|
+
*/
|
|
36
|
+
class JsonUtil {
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Validate that a string is valid JSON
|
|
40
|
+
* @param {string} json - JSON string to validate
|
|
41
|
+
* @throws {JsonValidationError} If JSON is invalid
|
|
42
|
+
*/
|
|
43
|
+
validateJson(json) {
|
|
44
|
+
try {
|
|
45
|
+
JSON.parse(json);
|
|
46
|
+
} catch (err) {
|
|
47
|
+
throw new JsonValidationError(json, err);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = new JsonUtil();</code></pre>
|
|
54
|
+
</article>
|
|
55
|
+
</section>
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
<nav>
|
|
63
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="BrowserApi.html">BrowserApi</a></li><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="CsvToJson.html">CsvToJson</a></li><li><a href="CsvToJsonAsync.html">CsvToJsonAsync</a></li><li><a href="FileOperationError.html">FileOperationError</a></li><li><a href="FileUtils.html">FileUtils</a></li><li><a href="InputValidationError.html">InputValidationError</a></li><li><a href="JsonUtil.html">JsonUtil</a></li><li><a href="JsonValidationError.html">JsonValidationError</a></li></ul><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#browser">browser</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>
|
|
64
|
+
</nav>
|
|
65
|
+
|
|
66
|
+
<br class="clear">
|
|
67
|
+
|
|
68
|
+
<footer>
|
|
69
|
+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.5</a> on Fri Mar 20 2026 14:48:29 GMT+0000 (Coordinated Universal Time)
|
|
70
|
+
</footer>
|
|
71
|
+
|
|
72
|
+
<script> prettyPrint(); </script>
|
|
73
|
+
<script src="scripts/linenumber.js"> </script>
|
|
74
|
+
</body>
|
|
75
|
+
</html>
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>JSDoc: Source: src/util/stringUtils.js</title>
|
|
6
|
+
|
|
7
|
+
<script src="scripts/prettify/prettify.js"> </script>
|
|
8
|
+
<script src="scripts/prettify/lang-css.js"> </script>
|
|
9
|
+
<!--[if lt IE 9]>
|
|
10
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
11
|
+
<![endif]-->
|
|
12
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
13
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
14
|
+
</head>
|
|
15
|
+
|
|
16
|
+
<body>
|
|
17
|
+
|
|
18
|
+
<div id="main">
|
|
19
|
+
|
|
20
|
+
<h1 class="page-title">Source: src/util/stringUtils.js</h1>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
<section>
|
|
28
|
+
<article>
|
|
29
|
+
<pre class="prettyprint source linenums"><code>'use strict';
|
|
30
|
+
|
|
31
|
+
class StringUtils {
|
|
32
|
+
// Regular expressions as constants for better maintainability
|
|
33
|
+
static PATTERNS = {
|
|
34
|
+
INTEGER: /^-?\d+$/,
|
|
35
|
+
FLOAT: /^-?\d*\.\d+$/,
|
|
36
|
+
WHITESPACE: /\s/g
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
static BOOLEAN_VALUES = {
|
|
40
|
+
TRUE: 'true',
|
|
41
|
+
FALSE: 'false'
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Removes whitespace from property names based on configuration
|
|
46
|
+
* @param {boolean} shouldTrimAll - If true, removes all whitespace, otherwise only trims edges
|
|
47
|
+
* @param {string} propertyName - The property name to process
|
|
48
|
+
* @returns {string} The processed property name
|
|
49
|
+
*/
|
|
50
|
+
trimPropertyName(shouldTrimAll, propertyName) {
|
|
51
|
+
if (!propertyName) {
|
|
52
|
+
return '';
|
|
53
|
+
}
|
|
54
|
+
return shouldTrimAll ?
|
|
55
|
+
propertyName.replace(StringUtils.PATTERNS.WHITESPACE, '') :
|
|
56
|
+
propertyName.trim();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Converts a string value to its appropriate type while preserving data integrity
|
|
61
|
+
* @param {string} value - The input value to convert
|
|
62
|
+
* @returns {string|number|boolean} The converted value
|
|
63
|
+
*/
|
|
64
|
+
getValueFormatByType(value) {
|
|
65
|
+
if (this.isEmpty(value)) {
|
|
66
|
+
return String();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (this.isBoolean(value)) {
|
|
70
|
+
return this.convertToBoolean(value);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (this.isInteger(value)) {
|
|
74
|
+
return this.convertInteger(value);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (this.isFloat(value)) {
|
|
78
|
+
return this.convertFloat(value);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return String(value);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Checks if a value array contains any non-empty values
|
|
86
|
+
* @param {Array} values - Array to check for content
|
|
87
|
+
* @returns {boolean} True if array has any non-empty values
|
|
88
|
+
*/
|
|
89
|
+
hasContent(values = []) {
|
|
90
|
+
return Array.isArray(values) &&
|
|
91
|
+
values.some(value => Boolean(value));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Private helper methods for type checking and conversion
|
|
95
|
+
/**
|
|
96
|
+
* Check if a value is empty (undefined or empty string)
|
|
97
|
+
* @param {*} value - Value to check
|
|
98
|
+
* @returns {boolean} True if value is undefined or empty string
|
|
99
|
+
* @private
|
|
100
|
+
*/
|
|
101
|
+
isEmpty(value) {
|
|
102
|
+
return value === undefined || value === '';
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Check if a value is a boolean string ('true' or 'false', case-insensitive)
|
|
107
|
+
* @param {string} value - Value to check
|
|
108
|
+
* @returns {boolean} True if value is 'true' or 'false'
|
|
109
|
+
* @private
|
|
110
|
+
*/
|
|
111
|
+
isBoolean(value) {
|
|
112
|
+
const normalizedValue = value.toLowerCase();
|
|
113
|
+
return normalizedValue === StringUtils.BOOLEAN_VALUES.TRUE ||
|
|
114
|
+
normalizedValue === StringUtils.BOOLEAN_VALUES.FALSE;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Check if a value is an integer string (with optional leading minus sign)
|
|
119
|
+
* @param {string} value - Value to check
|
|
120
|
+
* @returns {boolean} True if value matches integer pattern
|
|
121
|
+
* @private
|
|
122
|
+
*/
|
|
123
|
+
isInteger(value) {
|
|
124
|
+
return StringUtils.PATTERNS.INTEGER.test(value);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Check if a value is a float string (decimal number with optional leading minus sign)
|
|
129
|
+
* @param {string} value - Value to check
|
|
130
|
+
* @returns {boolean} True if value matches float pattern
|
|
131
|
+
* @private
|
|
132
|
+
*/
|
|
133
|
+
isFloat(value) {
|
|
134
|
+
return StringUtils.PATTERNS.FLOAT.test(value);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Check if a numeric string has a leading zero (e.g., '01' or '-01')
|
|
139
|
+
* Leading zeros indicate the value should be kept as a string to preserve formatting
|
|
140
|
+
* @param {string} value - Numeric string value to check
|
|
141
|
+
* @returns {boolean} True if value has a leading zero
|
|
142
|
+
* @private
|
|
143
|
+
*/
|
|
144
|
+
hasLeadingZero(value) {
|
|
145
|
+
const isPositiveWithLeadingZero = value.length > 1 && value[0] === '0';
|
|
146
|
+
const isNegativeWithLeadingZero = value.length > 2 && value[0] === '-' && value[1] === '0';
|
|
147
|
+
return isPositiveWithLeadingZero || isNegativeWithLeadingZero;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Convert a boolean string to native boolean value
|
|
152
|
+
* Safely converts 'true' to true and 'false' to false
|
|
153
|
+
* @param {string} value - Boolean string ('true' or 'false')
|
|
154
|
+
* @returns {boolean} Native boolean value
|
|
155
|
+
* @private
|
|
156
|
+
*/
|
|
157
|
+
convertToBoolean(value) {
|
|
158
|
+
return JSON.parse(value.toLowerCase());
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Convert an integer string to number or keep as string if it has leading zeros
|
|
163
|
+
* Preserves leading zeros in strings (e.g., '007' stays as string)
|
|
164
|
+
* @param {string} value - Integer string to convert
|
|
165
|
+
* @returns {number|string} Number if safe, otherwise string value
|
|
166
|
+
* @private
|
|
167
|
+
*/
|
|
168
|
+
convertInteger(value) {
|
|
169
|
+
if (this.hasLeadingZero(value)) {
|
|
170
|
+
return String(value);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const num = Number(value);
|
|
174
|
+
return Number.isSafeInteger(num) ? num : String(value);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Convert a float string to number or keep as string if conversion is unsafe
|
|
179
|
+
* @param {string} value - Float string to convert
|
|
180
|
+
* @returns {number|string} Number if finite and valid, otherwise string value
|
|
181
|
+
* @private
|
|
182
|
+
*/
|
|
183
|
+
convertFloat(value) {
|
|
184
|
+
const num = Number(value);
|
|
185
|
+
return Number.isFinite(num) ? num : String(value);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
module.exports = new StringUtils();
|
|
190
|
+
</code></pre>
|
|
191
|
+
</article>
|
|
192
|
+
</section>
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
</div>
|
|
198
|
+
|
|
199
|
+
<nav>
|
|
200
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="BrowserApi.html">BrowserApi</a></li><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="CsvToJson.html">CsvToJson</a></li><li><a href="CsvToJsonAsync.html">CsvToJsonAsync</a></li><li><a href="FileOperationError.html">FileOperationError</a></li><li><a href="FileUtils.html">FileUtils</a></li><li><a href="InputValidationError.html">InputValidationError</a></li><li><a href="JsonUtil.html">JsonUtil</a></li><li><a href="JsonValidationError.html">JsonValidationError</a></li></ul><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#browser">browser</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>
|
|
201
|
+
</nav>
|
|
202
|
+
|
|
203
|
+
<br class="clear">
|
|
204
|
+
|
|
205
|
+
<footer>
|
|
206
|
+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.5</a> on Fri Mar 20 2026 14:48:29 GMT+0000 (Coordinated Universal Time)
|
|
207
|
+
</footer>
|
|
208
|
+
|
|
209
|
+
<script> prettyPrint(); </script>
|
|
210
|
+
<script src="scripts/linenumber.js"> </script>
|
|
211
|
+
</body>
|
|
212
|
+
</html>
|