🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

@novigi/csv-to-json

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@novigi/csv-to-json

Simple library for csv parse to Javascript object from any CSV string or csv file 🚀

npmnpm
Version
1.0.0-1
Version published
Weekly downloads
7
75%
Maintainers
3
Weekly downloads
 
Created
Source

npm (scoped) NPM Statements Branches Functions Lines

@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

  • Install the dependency
npm install @novigi/csv-to-json
  • Import the library
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-to-json.parse(csvString, [customHeader]) ⇒ object

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

ParamTypeDefaultDescription
csvStringstringvalid 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)                              // [{ name: 'kasun', age: '33', sex: 'male' }, { name: 'steve', age: '35', sex: 'male' }]
csv.parse(csvString, ['user_name'])               // [{ user_name: 'kasun', age: '33', sex: 'male' }, { user_name: 'steve', age: '35', sex: 'male' }]
csv.parseFile(csvFile, ['user_name','user_age'])  // [{ user_name: 'kasun', user_age: '33', sex: 'male' }, { user_name: 'steve', user_age: '35', sex: 'male' }]

csv-to-json.parseFile(csvFile, [customHeader]) ⇒ object

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

ParamTypeDefaultDescription
csvFilestringvalid 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 file directory path
csv.parseFile(csvFile)                           // [{ name: 'kasun', age: '33', sex: 'male' }, { name: 'steve', age: '35', sex: 'male' }]
csv.parseFile(csvFile, ['user_name'])            // [{ user_name: 'kasun', age: '33', sex: 'male' }, { user_name: 'steve', age: '35', sex: 'male' }]
csv.parseFile(csvFile, ['user_name','user_age']) // [{ user_name: 'kasun', user_age: '33', sex: 'male' }, { user_name: 'steve', user_age: '35', sex: 'male' }]

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

ParamTypeDescription
delimiterstringdelimiter 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)                       // default delimiter can be use without pass the delimiter function
csv.fieldDelimiter(';').parse(csvString)   // [{ name: 'kasun', age: '33', sex: 'male' }, { name: 'steve', age: '35', sex: 'male' }]

This is an auto generated file. Please don't make changes manually

FAQs

Package last updated on 10 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts