A simple javascript TSV/CSV parser.
JavaScript CoffeeScript
Switch branches/tags
Nothing to show
Latest commit ac61fe2 Nov 7, 2016 @ricardobeat scare people away
Permalink
Failed to load latest commit information.
test Fix dependencies for Mar 13, 2013
.gitignore Add back test.csv, close #1 Mar 13, 2013
README.md scare people away Nov 7, 2016
index.js fix float detection, fixes #1 Nov 7, 2016
package.json Fix dependencies for Mar 13, 2013
project.sublime-project project files Jan 18, 2013

README.md

TSV

TSV/CSV converter and parser. Good for serving time-series (or any series) data to use in D3.js or other client-side graph libraries.

Warning: This module does very dumb parsing and is not suitable for unclean data not generated by yourself. Processing is synchronous. Not suitable for large datasets. Unless you're really into minimal code, please use a better supported tool like node-csv-parser.

Install

npm install tsv

Usage

var csv = require('csv')
var tsv = require('xsv').tsv
{ tsv, csv } = require 'xsv' // coffeescript

The data argument for stringify must be a flat array of objects. Keys will be derived from the first item.

TSV.stringify([
    { id: 1, name: 'xx' },
    { id: 2, name: 'yy' }
    ...
])

Outputs

id  name
1   xx
2   yy

API

  • TSV.stringify(object)
  • TSV.parse(tsv_string)
  • CSV.stringify(object)
  • CSV.parse(csv_string)

Options and custom separators

No headers:

// Creating a new parser
var Parser = require('tsv').Parser
var CSV = new Parser(",", { header: false })

// Using the default parser
var CSV = require('tsv').CSV
CSV.header = false

Custom "pipe-separated values":

var TSV = require('tsv')
PSV = new TSV.Parser("|")

var res = PSV.parse(...)