convert-csv-to-json 2.37.0 → 2.38.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/index.d.ts ADDED
@@ -0,0 +1,98 @@
1
+ declare module 'convert-csv-to-json' {
2
+ export class ConvertCsvToJson {
3
+ /**
4
+ * Prints a digit as Number type (for example 32 instead of '32')
5
+ */
6
+ formatValueByType(active: boolean): this;
7
+
8
+ /**
9
+ *
10
+ */
11
+ supportQuotedField(active: boolean): this;
12
+ /**
13
+ * Defines the field delimiter which will be used to split the fields
14
+ */
15
+ fieldDelimiter(delimiter: string): this;
16
+
17
+ /**
18
+ * Defines the index where the header is defined
19
+ */
20
+ indexHeader(index: number): this;
21
+
22
+ /**
23
+ * Defines how to match and parse a sub array
24
+ */
25
+ parseSubArray(delimiter: string, separator: string): this;
26
+
27
+ /**
28
+ * Defines a custom encoding to decode a file
29
+ */
30
+ customEncoding(encoding: string): this;
31
+
32
+ /**
33
+ * Defines a custom encoding to decode a file
34
+ */
35
+ utf8Encoding(): this;
36
+
37
+ /**
38
+ * Defines ucs2 encoding to decode a file
39
+ */
40
+ ucs2Encoding(): this;
41
+
42
+ /**
43
+ * Defines utf16le encoding to decode a file
44
+ */
45
+ utf16leEncoding(): this;
46
+
47
+ /**
48
+ * Defines latin1 encoding to decode a file
49
+ */
50
+ latin1Encoding(): this;
51
+
52
+ /**
53
+ * Defines ascii encoding to decode a file
54
+ */
55
+ asciiEncoding(): this;
56
+
57
+ /**
58
+ * Defines base64 encoding to decode a file
59
+ */
60
+ base64Encoding(): this;
61
+
62
+ /**
63
+ * Defines hex encoding to decode a file
64
+ */
65
+ hexEncoding(): this;
66
+
67
+ /**
68
+ * Parses .csv file and put its content into a file in json format.
69
+ * @param {inputFileName} path/filename
70
+ * @param {outputFileName} path/filename
71
+ *
72
+ */
73
+ generateJsonFileFromCsv(
74
+ inputFileName: string,
75
+ outputFileName: string,
76
+ ): void;
77
+
78
+ /**
79
+ * Parses .csv file and put its content into an Array of Object in json format.
80
+ * @param {inputFileName} path/filename
81
+ * @return {Array} Array of Object in json format
82
+ *
83
+ */
84
+ getJsonFromCsv(inputFileName: string): any[];
85
+
86
+ csvStringToJson(csvString: string): any[];
87
+ /**
88
+ * Parses .csv file and put its content into a file in json format.
89
+ * @param {inputFileName} path/filename
90
+ * @param {outputFileName} path/filename
91
+ *
92
+ * @deprecated Use generateJsonFileFromCsv()
93
+ */
94
+ jsonToCsv(inputFileName: string, outputFileName: string): void;
95
+ }
96
+ const converter: ConvertCsvToJson;
97
+ export default converter;
98
+ }
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "convert-csv-to-json",
3
- "version": "2.37.0",
3
+ "version": "2.38.0",
4
4
  "description": "Convert CSV to JSON",
5
5
  "main": "index.js",
6
+ "types": "index.d.ts",
6
7
  "scripts": {
7
8
  "test": "jest",
8
9
  "test-debug": "node --inspect-brk node_modules/.bin/jest --runInBand --detectOpenHandles",
package/src/csvToJson.js CHANGED
@@ -69,8 +69,14 @@ class CsvToJson {
69
69
  let lines = parsedCsv.split(newLine);
70
70
  let fieldDelimiter = this.getFieldDelimiter();
71
71
  let index = this.getIndexHeader();
72
- let headers = lines[index].split(fieldDelimiter);
73
-
72
+ let headers;
73
+
74
+ if(this.isSupportQuotedField){
75
+ headers = this.split(lines[index]);
76
+ } else {
77
+ headers = lines[index].split(fieldDelimiter);
78
+ }
79
+
74
80
  while(!stringUtils.hasContent(headers) && index <= lines.length){
75
81
  index = index + 1;
76
82
  headers = lines[index].split(fieldDelimiter);