csv-parse
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "csv-parse" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-680a52b18585a04dfdba01aa11c3f059b5441bf8b217ba41118e8eb273cb4b13. Verify the upstream source and version against https://github.com/TerminalSkills/skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Parse and generate CSV files using the csv package — supports streaming large files, custom delimiters, record transformation and validation, and generating CSV output from objects. Suitable for data import/export, ETL pipelines, handling uploaded CSVs, or producing downloadable reports.
Introduction source: third_party · TerminalSkills · 1.0.0 Reference
SkillPi interpretation
- Software, accounts and paid services
- ```bash
- Testing
- Not tested
Browse files
Frontmatter
name: csv-parse
description: >-
Parse and generate CSV files with the csv package — stream large files,
handle custom delimiters, transform records, validate data, and generate
CSV output from objects. Use when tasks involve data import/export, ETL
pipelines, processing uploaded CSV files, or generating downloadable reports.
license: Apache-2.0
compatibility: "Node.js 14+ or browser"
metadata:
author: terminal-skills
version: "1.0.0"
category: documents
tags: ["csv", "parsing", "streaming", "data-import", "export"]csv-parse
Parse and stringify CSV data. Streaming architecture handles files of any size.
Setup
# Install the csv package (includes parse, stringify, transform, generate).
npm install csv
# Or install individual packages:
npm install csv-parse csv-stringify
Parsing a CSV File
// src/csv/parse-file.ts — Read a CSV file and convert rows to objects.
// Uses the header row as keys for each record object.
import { parse } from "csv-parse";
import fs from "fs";
export async function parseCsvFile(filePath: string): Promise<Record<string, string>[]> {
const records: Record<string, string>[] = [];
const parser = fs.createReadStream(filePath).pipe(
parse({
columns: true, // use first row as headers
skip_empty_lines: true,
trim: true,
})
);
for await (const record of parser) {
records.push(record);
}
return records;
}
Parsing a CSV String
// src/csv/parse-string.ts — Parse CSV data from a string (e.g., API response body).
import { parse } from "csv-parse/sync";
export function parseCsvString(csvData: string) {
return parse(csvData, {
columns: true,
skip_empty_lines: true,
cast: true, // auto-cast numbers and booleans
cast_date: true, // auto-cast ISO date strings
});
}
Generating CSV Output
// src/csv/stringify.ts — Convert objects to CSV strings for download or file export.
import { stringify } from "csv-stringify/sync";
interface SalesRow {
product: string;
revenue: number;
units: number;
date: string;
}
export function generateCsv(data: SalesRow[]): string {
return stringify(data, {
header: true,
columns: [
{ key: "product", header: "Product Name" },
{ key: "revenue", header: "Revenue ($)" },
{ key: "units", header: "Units Sold" },
{ key: "date", header: "Date" },
],
});
}
Streaming Large Files
// src/csv/stream.ts — Process million-row CSV files without loading into memory.
// Transform each record as it streams through.
import { parse } from "csv-parse";
import { stringify } from "csv-stringify";
import { transform } from "stream-transform";
import fs from "fs";
export function transformCsv(inputPath: string, outputPath: string) {
fs.createReadStream(inputPath)
.pipe(parse({ columns: true }))
.pipe(
transform((record: any) => ({
name: record.name.toUpperCase(),
email: record.email.toLowerCase(),
total: Number(record.price) * Number(record.quantity),
}))
)
.pipe(stringify({ header: true }))
.pipe(fs.createWriteStream(outputPath));
}
Custom Delimiters
// src/csv/delimiters.ts — Handle TSV files, semicolon-separated, or pipe-delimited.
import { parse } from "csv-parse/sync";
// Tab-separated values
const tsvData = "name\tage\tcity\nAlice\t30\tPrague";
const tsvRecords = parse(tsvData, { columns: true, delimiter: "\t" });
// Semicolon-separated (common in European exports)
const csvData = "name;age;city\nAlice;30;Prague";
const csvRecords = parse(csvData, { columns: true, delimiter: ";" });
Validation
// src/csv/validate.ts — Validate CSV records during parsing and collect errors.
import { parse } from "csv-parse";
import fs from "fs";
interface ValidationError {
line: number;
field: string;
message: string;
}
export async function validateCsv(
filePath: string,
requiredFields: string[]
): Promise<{ valid: any[]; errors: ValidationError[] }> {
const valid: any[] = [];
const errors: ValidationError[] = [];
const parser = fs.createReadStream(filePath).pipe(
parse({ columns: true, skip_empty_lines: true })
);
let line = 1;
for await (const record of parser) {
line++;
let hasError = false;
for (const field of requiredFields) {
if (!record[field] || record[field].trim() === "") {
errors.push({ line, field, message: `Missing required field: ${field}` });
hasError = true;
}
}
if (!hasError) valid.push(record);
}
return { valid, errors };
}
Express API Endpoint
// src/csv/api.ts — API endpoint that generates and streams a CSV download.
import { stringify } from "csv-stringify";
import type { Request, Response } from "express";
export function handleCsvExport(req: Request, res: Response, data: any[]) {
res.setHeader("Content-Type", "text/csv");
res.setHeader("Content-Disposition", "attachment; filename=export.csv");
const stringifier = stringify({ header: true });
stringifier.pipe(res);
for (const row of data) {
stringifier.write(row);
}
stringifier.end();
}Current listing version
1.0.0
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 覆盖 CSV 解析、生成、流式处理、自定义分隔符、数据验证等完整功能链
- 适用于数据导入/导出、ETL 流水线等高频刚需场景
Highlights
- description 明确描述使用场景,触发词精准,边界清晰
Areas to improve
-
缺少 When to Use 章节 Reported severity: Minor
文档结构完整但缺少显式的 When to Use 使用场景说明章节
Recommendation: 建议在文档开头补充 When to Use 章节,明确列出典型使用场景
Highlights
- 文档结构清晰,分多个功能模块,每部分含完整代码示例
- frontmatter 完整,单文件未超 500 行
Highlights
- 所有代码示例均基于标准 csv 包,参数正确
- 涵盖异常处理与流式处理,避免内存溢出风险
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Install or fetch external dependencies
Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.
Mentioned in main document · lines 25, 27
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
```bash
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.