
@novigi/csv-to-json
Simple library for csv parse to Javascript object from any CSV string or csv file 🚀
🐿 Features
- CSV to javascript object chainable API
- CSV parse to JAVASCRIPT object
- CSV file read and parse to object
📦 Getting Started
npm install @novigi/csv-to-json
const lib = require('@novigi/csv-to-json');
📖 Documentation
csv-to-json
This library contains methods that allow to user parse the csv
either it is a csv string or file convert into the Javscript object
This guideline is about the formats and examples that can follow for csv string parsing to Javascript object conversion 🚀
const { csv } = require('@novigi/csv-to-json');
csv parse to javascript data structure , 'parse' method convert the csv string to the javascript array object
Kind: static method of csv-to-json
Returns: object - string CSV and parse it into a javascript data structure
| csvString | string | | valid string to passes as a parameter |
| [customHeader] | array | [] | a list of header names passes as a custom header ,if customer header is in the object it will replace the header name otherwise it takes the same name in the header |
Example
const csvString = "name,age,sex\nkasun,33,male\nsteve,35,male"
csv.parse(csvString)
csv.parse(csvString, ['user_name'])
csv.parseFile(csvFile, ['user_name','user_age'])
csv file read and parse to javascript data structure , 'parseFile' method read and convert the csv file into the javascript array object
Kind: static method of csv-to-json
Returns: object - CSV file and parse it into a javascript data structure
| csvFile | string | | valid csv file path , the path passes as a parameter and read the file in that file is exist |
| [customHeader] | array | [] | a list of header names passes as a custom header ,if customer header is in the object it will replace the header name otherwise it takes the same name in the header |
Example
const path = './resources/csvFile.csv'
csv.parseFile(csvFile)
csv.parseFile(csvFile, ['user_name'])
csv.parseFile(csvFile, ['user_name','user_age'])
csv-to-json.fieldDelimiter(delimiter)
delimiter is for different separators can manually pass with csv file or string , the separator separate the csv string in the context
Kind: static method of csv-to-json
| delimiter | string | delimiter separator , the delimiter as a parameter to separate the values in the csv |
Example
const csvString = "name;age;sex\nkasun;33;male\nsteve;35;male"
csv.parse(csvString)
csv.fieldDelimiter(';').parse(csvString)
This is an auto generated file. Please don't make changes manually