Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tsv

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsv - npm Package Compare versions

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc