JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 40001
  • Score
    100M100P100Q172534F
  • License MIT (ricardo.mit-license.org)

Simple dependency-free TSV and CSV converter/parser

Package Exports

  • tsv

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (tsv) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

TSV

Simple 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.

Processing is synchronous. Do not use for large datasets - use something that supports streams instead, 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(...)