Socket
Socket
Sign inDemoInstall

csv-table-parser

Package Overview
Dependencies
1
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    csv-table-parser

convert csv to object array


Version published
Weekly downloads
2
Maintainers
1
Install size
142 kB
Created
Weekly downloads
 

Readme

Source

build_status build_status MIT License

how to install

 npm install csv-table-parser

what's this?

csv file convert to object array like below.

const { parser } = require('csv-table-parser')

const input = `name, age, email, isMember
alice, 15, alice@xxx.com, true
bob, 25, bob@xxx.com, false
`

parser(input)
/*
 *[
 *   { name: "alice", age: 15, email: "alice@xxx.com", isMember: true },
 *   { name: "bob", age: 25, email: "bob@xxx.com", isMember: false }
 *]
*/

you can also convert to array in array.

const { parser } = require('csv-table-parser')

const input = `alice, 15, alice@xxx.com, true
bob, 25, bob@xxx.com, false
`

parser(input, { type: 'array' })
/*
 *[
 *   [ "alice", 15, "alice@xxx.com", true ],
 *   [ "bob", 25, "bob@xxx.com", false ]
 *]
*/

options

second parameter is options. the example is below.

separator

const input = `name	age	email	isMember
alice	15	alice@xxx.com	true
bob	25	bob@xxx.com	false
`

parser(input, { separator: '\t' })
/*
 *[
 *   { name: "alice", age: 15, email: "alice@xxx.com", isMember: true },
 *   { name: "bob", age: 25, email: "bob@xxx.com", isMember: false }
 *]
*/

startRow

const input = `customer name, customer age, customer email for customer service, this user is member or not
name, age, email, isMember
alice, 15, alice@xxx.com, true
bob, 25, bob@xxx.com, false
`

parser(input, { startRow: 1 })
/*
 *[
 *   { name: "alice", age: 15, email: "alice@xxx.com", isMember: true },
 *   { name: "bob", age: 25, email: "bob@xxx.com", isMember: false }
 *]
*/

startColumn

const input = `no, name, age, email, isMember
1, alice, 15, alice@xxx.com, true
2, bob, 25, bob@xxx.com, false
`

parser(input, { startColumn: 1 })
/*
 *[
 *   { name: "alice", age: 15, email: "alice@xxx.com", isMember: true },
 *   { name: "bob", age: 25, email: "bob@xxx.com", isMember: false }
 *]
*/

numberOfColumn

const input = `name, age, email, isMember
alice, 15, alice@xxx.com, true
bob, 25, bob@xxx.com, false
`

parser(input, { numberOfColumn: 3 })
/*
 *[
 *   { name: "alice", age: 15, email: "alice@xxx.com" },
 *   { name: "bob", age: 25, email: "bob@xxx.com" }
 *]
*/

defaultValue

const input = `name, age, email, isMember
alice, 15, alice@xxx.com,
bob, 25, bob@xxx.com, true
`

parser(input, { defaultValue: false })
/*
 *[
 *   { name: "alice", age: 15, email: "alice@xxx.com", isMember: false },
 *   { name: "bob", age: 25, email: "bob@xxx.com", isMember: true }
 *]
*/

FAQs

Last updated on 17 Feb 2018

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc