convert-csv-to-json
Advanced tools
Comparing version 0.0.7 to 0.0.8
{ | ||
"name": "convert-csv-to-json", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Convert CSV to JSON", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,4 @@ | ||
# CSVtoJSON [![Build Status](https://travis-ci.org/iuccio/csvToJson.svg?branch=master)](https://travis-ci.org/iuccio/csvToJson) | ||
# CSVtoJSON | ||
[![Build Status](https://travis-ci.org/iuccio/csvToJson.svg?branch=master)](https://travis-ci.org/iuccio/csvToJson) [![Code Climate](https://codeclimate.com/github/iuccio/csvToJson/badges/gpa.svg)](https://codeclimate.com/github/iuccio/csvToJson) | ||
Convert *csv* file to *JSON* file with Node.js. | ||
@@ -80,3 +82,3 @@ | ||
#### Format property value by type | ||
If you want that a number will be printed as a Numbert type and not as a String type, use: | ||
If you want that a number will be printed as a Number type and not as a String type, use: | ||
```js | ||
@@ -94,3 +96,3 @@ csvToJson.formatValueByType().getJsonFromCsv(fileInputName) | ||
"gender": "Male", | ||
"age": 96 //instead of "96" | ||
"age": 96 | ||
}, | ||
@@ -102,9 +104,17 @@ { | ||
"gender": "Female", | ||
"age": 32 //instead of "32" | ||
"age": 32 | ||
} | ||
] | ||
``` | ||
The property **age** is printed as | ||
```json | ||
"age": 32 | ||
``` | ||
instead of | ||
```json | ||
"age": "32" | ||
``` | ||
## License | ||
CSVtoJSON is licensed under the GNU General Public License v3.0 [License](LICENSE). |
@@ -12,3 +12,3 @@ 'use strict'; | ||
formatValueByType(){ | ||
formatValueByType() { | ||
this.printValueFormatByType = true; | ||
@@ -41,5 +41,6 @@ return this; | ||
for (let i = 1; i < lines.length; i++) { | ||
let currentLine = lines[i].split(fieldDelimiter); | ||
let currentLine = lines[i].replace(/""/g, '"').split(fieldDelimiter); | ||
console.log('CURRENT LINE\N ' + currentLine); | ||
if (stringUtils.hasContent(currentLine)) { | ||
jsonResult.push(this.buildJsonResult(headers,currentLine)); | ||
jsonResult.push(this.buildJsonResult(headers, currentLine)); | ||
} | ||
@@ -50,3 +51,3 @@ } | ||
buildJsonResult(headers,currentLine){ | ||
buildJsonResult(headers, currentLine) { | ||
let jsonObject = {}; | ||
@@ -57,3 +58,3 @@ for (let j = 0; j < headers.length; j++) { | ||
let value = currentLine[j]; | ||
if(this.printValueFormatByType){ | ||
if (this.printValueFormatByType) { | ||
value = stringUtils.getValueFormatByType(currentLine[j]); | ||
@@ -60,0 +61,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
155
118
93705