Working with TSV in TypeScript
Updated Nov 12, 2026
Tab-separated values (TSV) file handling with automatic format detection.
Installation
npm install fairspecGetting Started
The TSV format is handled by the CSV plugin, which provides:
loadCsvTable- Load TSV files into tablessaveCsvTable- Save tables to TSV filesCsvPlugin- Plugin for framework integration
For example:
import { loadCsvTable } from "fairspec"
const table = await loadCsvTable({ data: "table.tsv" })
// the column types will be automatically inferredLoaders return a nodejs-polars LazyDataFrame: call .collect() to get a DataFrame. Savers take any LazyDataFrame, so pass df.lazy() to save a DataFrame.
Basic Usage
Loading TSV Files
import { loadCsvTable } from "fairspec"
// Load a simple TSV file
const local = await loadCsvTable({ data: "data.tsv" })
// Load with explicit format
const custom = await loadCsvTable({
data: "data.tsv",
fileDialect: {
format: "tsv",
headerRows: [1],
},
})
// Load multiple TSV files (concatenated)
const combined = await loadCsvTable({
data: ["part1.tsv", "part2.tsv", "part3.tsv"],
})Saving TSV Files
import { saveCsvTable } from "fairspec"
// Save with default options
await saveCsvTable(table, {
path: "output.tsv",
fileDialect: { format: "tsv" },
})
// Save with line terminator option
await saveCsvTable(table, {
path: "output.tsv",
fileDialect: {
format: "tsv",
lineTerminator: "\r\n",
},
})Advanced Features
Multi-Header Row Processing
import { loadCsvTable } from "fairspec"
// TSV with multiple header rows
const table = await loadCsvTable({
data: "multi-header.tsv",
fileDialect: {
format: "tsv",
headerRows: [1, 2],
headerJoin: "_",
},
})Comment Handling
import { loadCsvTable } from "fairspec"
// TSV with comment lines
const byCommentPrefix = await loadCsvTable({
data: "with-comments.tsv",
fileDialect: {
format: "tsv",
commentPrefix: "#",
headerRows: [1],
},
})
// Or specify specific comment row numbers
const byCommentRows = await loadCsvTable({
data: "with-comments.tsv",
fileDialect: {
format: "tsv",
commentRows: [1, 2],
headerRows: [3],
},
})Remote File Loading
import { loadCsvTable } from "fairspec"
// Load from URL
const remote = await loadCsvTable({
data: "https://example.com/data.tsv",
})
// Load multiple remote files
const remoteParts = await loadCsvTable({
data: [
"https://api.example.com/data-2023.tsv",
"https://api.example.com/data-2024.tsv",
],
})Created with โค and Livemark