npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2024 – Pkg Stats / Ryan Hefner

@novigi/csv-to-json

v1.0.0-2

Published

Simple library for csv parse to Javascript object from any CSV string or csv file πŸš€

Downloads

8

Readme

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

  • Chainable and immutable API
  • Parse CSV content into JSON object
  • Parse CSV files into JSON objects
  • Supports custom headers

πŸ“¦ Getting Started

  1. Install the dependency
npm install @novigi/csv-to-json
  1. Import the library
const lib = require('@novigi/csv-to-json');

πŸ“– Documentation

csv-to-json

This library contains methods that allow user to 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')

const input = 'name,age,sex\nkasun,33,male\nsteve,35,male'
let json = csv().parseData(input)

// or

let json = csv().parseFile(path/to/file)

Chainable + immutable methods! ☝

csv-to-json~Csv

Kind: inner class of csv-to-json

csv.delimiter β‡’ Csv

Delimiter is for different separators that can manually pass with csv file or string, the separator separates the CSV string in the context.

Kind: instance property of Csv
Returns: Csv - new instance of Csv object with the same options

| Param | Type | Description | | --- | --- | --- | | delimiter | string | 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().fieldDelimiter(';').parseData(csvString)   // [{ name: 'kasun', age: '33', sex: 'male' }, { name: 'steve', age: '35', sex: 'male' }]

csv.lineBreak β‡’ Csv

Line-break is for for indicating the ending of a row in the csv content.

Kind: instance property of Csv
Returns: Csv - new instance of Csv object with the same options

| Param | Type | Description | | --- | --- | --- | | lineBreak | string | The lineBreak as a parameter to separate the lines in the csv |

Example

const csvString = "name,age,sex\r\nkasun,33,male\r\nsteve,35,male"
csv().lineBreak('\r\n').parseData(csvString)   // [{ name: 'kasun', age: '33', sex: 'male' }, { name: 'steve', age: '35', sex: 'male' }]

csv.noHeaders β‡’ Csv

This method is to indicate whether csv content has the header data or not.

Kind: instance property of Csv
Returns: Csv - new instance of Csv object with the same options

| Param | Type | Description | | --- | --- | --- | | noHeaders | * | Indicate whether csv content has headers. Undefined parameter is considered as true |

Example

const csvString = 'kasun,33,male\nsteve,35,male'
const customHeader = ['user_name', 'user_age', 'user_gender']
const result = csv().noHeaders().headers(customHeader).parseData(csvString) // custom headers wil be used as the headers of the csv content

csv.headers β‡’ Csv

Adds headers to use as the headers of the csv content. Specifying headers will override the headers in the csv content. When provided header list is insufficient, headers in the csv content are considered

Kind: instance property of Csv
Returns: Csv - new instance of Csv object with the same options

| Param | Type | Description | | --- | --- | --- | | headers | array | Custom header array to be used as headers of the csv content |

Example

const csvString = 'kasun,33,male\nsteve,35,male'
const customHeader = ['user_name', 'user_age', 'user_gender']
const result = csv().headers(customHeader).parseData(csvString)

csv.parseFile β‡’ Csv

CSV file read and parse to javascript data structure , 'parseFile' method read and convert the csv file into the javascript array object.

Kind: instance property of Csv
Returns: Csv - new instance of Csv object with the same options

| Param | Type | Description | | --- | --- | --- | | csvFile | string | valid csv file path , the path passes as a parameter and read the file in that file is exist |

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.parseData β‡’ Csv

CSV parse to javascript data structure,'parse' method convert the csv string to the javascript array object.

Kind: instance property of Csv
Returns: Csv - new instance of Csv object with the same options

| Param | Type | Description | | --- | --- | --- | | csvString | string | valid string to passes as a parameter |

Example

const csvString = "name,age,sex\nkasun,33,male\nsteve,35,male"
csv().parseData(csvString)                              // [{ name: 'kasun', age: '33', sex: 'male' }, { name: 'steve', age: '35', sex: 'male' }]

csv-to-json~csv([options]) β‡’ Csv

Create an Csv chain builder instance

Kind: inner method of csv-to-json
Returns: Csv - new instance of 'Csv' object

| Param | Type | Description | | --- | --- | --- | | [options] | object | optional configurations for the chain | | [options.delimiter] | string | delimiter which csv fields are separated | | [options.lineBreak] | string | line break character of csv rows | | [options.noHeaders] | boolean | falg to indicate csv content has a header row or not | | [options.headers] | object | custom headers for parsing csv content |

Example

csv()
csv(options)

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