{"id":40784,"library":"csv-formatter","title":"csv-formatter","description":"A streaming CSV formatter for Node.js that transforms arrays of objects into CSV strings. Current stable version is 1.1.0. It aims for compatibility with the csv-spectrum CSV acid test suite. Key differentiators include streaming support (ideal for large datasets), customizable separator and newline, and the ability to specify headers explicitly or derive them from the first object. It can be used in the browser with browserify. The package is lightweight with no dependencies.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/holodex/csv-formatter","tags":["javascript","csv","tsv","format","formatter"],"install":[{"cmd":"npm install csv-formatter","lang":"bash","label":"npm"},{"cmd":"yarn add csv-formatter","lang":"bash","label":"yarn"},{"cmd":"pnpm add csv-formatter","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports a single function. In CommonJS, use require('csv-formatter') which returns the function directly.","wrong":"const { csv } = require('csv-formatter')","symbol":"default","correct":"import csv from 'csv-formatter'"},{"note":"CommonJS import: require returns the function itself, not an object.","wrong":"const { default: csv } = require('csv-formatter')","symbol":"require('csv-formatter')","correct":"const csv = require('csv-formatter')"},{"note":"TypeScript users should use default import; the module has esModuleInterop behavior or use `import csv = require('csv-formatter')`.","wrong":"import * as csv from 'csv-formatter'","symbol":"default (TypeScript)","correct":"import csv from 'csv-formatter'"}],"quickstart":{"code":"import csv from 'csv-formatter';\nimport { Readable } from 'stream';\n\nconst data = [\n  { name: 'Alice', age: 30 },\n  { name: 'Bob', age: 25 }\n];\n\nconst readable = Readable.from(data);\nconst csvStream = readable.pipe(csv());\n\ncsvStream.on('data', chunk => {\n  console.log(chunk.toString());\n  // Output: \"name,age\\nAlice,30\\nBob,25\\n\"\n});","lang":"javascript","description":"Demonstrates streaming CSV formatting from an array of objects to a CSV string."},"warnings":[{"fix":"Always specify headers explicitly via options or array to ensure all fields are included.","message":"Headers are derived from the first object's keys if not explicitly provided. If the first object lacks some keys that later objects have, those keys will be missing from output.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure piped data consists of plain JavaScript objects.","message":"The package expects object streams; passing non-objects may cause unexpected behavior.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Consider using a more robust CSV library if you need full RFC 4180 compliance.","message":"The output does not handle special characters (quotes, commas, newlines) according to CSV standards automatically; the package relies on csv-spectrum, but basic escaping may be incomplete.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'1.1.0':22 'abil':51 'acid':33 'aim':24 'array':12 'browser':69 'browserifi':71 'compat':26 'csv':2,6,16,30,32,80 'csv-formatt':1 'csv-spectrum':29 'current':18 'customiz':45 'dataset':44 'depend':78 'deriv':57 'differenti':37 'explicit':55 'first':61 'format':82 'formatt':3,7,83 'header':54 'ideal':41 'includ':38 'javascript':79 'key':36 'larg':43 'lightweight':75 'newlin':48 'node.js':9 'object':14,62 'packag':73 'separ':46 'specifi':53 'spectrum':31 'stabl':19 'stream':5,39 'string':17 'suit':35 'support':40 'test':34 'transform':11 'tsv':81 'use':66 'version':20","created_at":"2026-06-04T18:49:14.422429+00:00","updated_at":"2026-06-04T18:49:14.422429+00:00","problems":[{"fix":"Use `import csv from 'csv-formatter'` with ESM or `const csv = require('csv-formatter')` with CommonJS.","cause":"Default import from CommonJS module without proper interop.","error":"TypeError: csv is not a function"},{"fix":"Ensure you call csv() (e.g., .pipe(csv())) not just csv.","cause":"csv() returns a transform stream; forgetting to call it as a function.","error":"Cannot read property 'pipe' of undefined"},{"fix":"Add import { Readable } from 'stream' or const { Readable } = require('stream').","cause":"Missing import of Readable from 'stream' in Node.js.","error":"ReferenceError: Readable is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/holodex/csv-formatter#readme","github":"https://github.com/holodex/csv-formatter","docs":null,"changelog":null,"pypi":null,"npm":"csv-formatter","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}