Comparing version 0.1.0 to 0.1.1
32
index.js
(function(){ | ||
var TSV = {} | ||
, sep = "\t" | ||
, br = "\n" | ||
var br = "\n" | ||
TSV.stringify = function (data) { | ||
var keys = Object.keys(data[0]) | ||
function stringify (data) { | ||
var sep = this.sep | ||
, keys = Object.keys(data[0]) | ||
, header = keys.join(sep) | ||
@@ -25,4 +24,5 @@ , output = header + br | ||
TSV.parse = function (tsv) { | ||
var lines = tsv.split(/[\n\r]/).filter(comments) | ||
function parse (tsv) { | ||
var sep = this.sep | ||
, lines = tsv.split(/[\n\r]/).filter(comments) | ||
, keys = lines.shift().split(sep) | ||
@@ -39,2 +39,20 @@ | ||
var TSV = { | ||
stringify: stringify | ||
, parse: parse | ||
, sep: "\t" | ||
} | ||
// cyclical reference to allow both | ||
// var TSV = require('tsv') | ||
// and | ||
// { TSV, CSV } = require('tsv') | ||
TSV.TSV = TSV | ||
TSV.CSV = { | ||
stringify: stringify | ||
, parse: parse | ||
, sep: "," | ||
} | ||
if (typeof module !== 'undefined' && module.exports){ | ||
@@ -41,0 +59,0 @@ module.exports = TSV |
{ | ||
"name": "tsv", | ||
"description": "Small sync TSV converter/parser", | ||
"version": "0.1.0", | ||
"description": "Simple dependency-free TSV and CSV converter/parser", | ||
"version": "0.1.1", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
TSV | ||
=== | ||
JSON-to-TSV and vice-versa converter. Good for efficiently serving data to D3 while keeping a readable format. | ||
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](http://npmjs.org/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)` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4485
73
37