{"id":16641790,"url":"https://github.com/samthor/but-csv","last_synced_at":"2025-03-16T22:31:31.195Z","repository":{"id":43750899,"uuid":"457795959","full_name":"samthor/but-csv","owner":"samthor","description":"479 byte CSV parser and builder","archived":false,"fork":false,"pushed_at":"2024-08-08T04:29:37.000Z","size":82,"stargazers_count":24,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-13T17:54:02.854Z","etag":null,"topics":["csv","javascript"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/but-csv","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samthor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-10T13:41:12.000Z","updated_at":"2025-01-31T14:35:36.000Z","dependencies_parsed_at":"2024-08-08T06:29:26.702Z","dependency_job_id":null,"html_url":"https://github.com/samthor/but-csv","commit_stats":{"total_commits":60,"total_committers":5,"mean_commits":12.0,"dds":"0.43333333333333335","last_synced_commit":"4fa8955d2229cc37e468c313b95e73568ea35a25"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fbut-csv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fbut-csv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fbut-csv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fbut-csv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samthor","download_url":"https://codeload.github.com/samthor/but-csv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243830952,"owners_count":20354854,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","javascript"],"created_at":"2024-10-12T07:47:52.690Z","updated_at":"2025-03-16T22:31:30.804Z","avatar_url":"https://github.com/samthor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# but-csv\n\n\u003cimg src=\"https://storage.googleapis.com/hwhistlr.appspot.com/assets/but-csv.png\" width=\"64\" height=\"64\" align=\"right\" hspace=\"8\" /\u003e\n\n479 byte (minified) CSV parser and builder.\nSmaller when compressed.\nBuilt in ESM only.\n\nDoesn't care about headers, keyed rows, anything but strings.\nJust supports the CSV spec including multi-line and quoted strings.\n\nDoes not support:\n- `\\r\\n` (old DOS newlines)\n- streaming\n\nIf you need those features, try [tiddlycsv](https://www.npmjs.com/package/tiddlycsv), which is a bit bigger.\nThis package is intentionally tiny, mostly to prove a point.\n\n## Usage\n\nInstall via you favourite package manager and import `but-csv`.\nHas zero dependencies (obviously).\n\n```bash\n$ npm install but-csv\n```\n\n### Parse\n\nParses a CSV into an array of array of strings.\nSupports varied line lengths.\nDoes not convert to numbers or any other formats.\n\n```js\nimport { parse } from 'but-csv';\n\nconst out = parse('foo,bar,zing\\n1,2,3\\n4,5');\n// out will be [['foo', 'bar', 'zing'], ['1', '2', '3'], ['4','5']]\n```\n\nOnly supports passing a `string` (not a `Buffer` or friends).\nNode's operations on `string` are so much faster than on raw bytes (10x improvement).\nIf you're parsing a file, do this:\n\n```js\nconst f = fs.readFileSync('source.csv', 'utf-8');\nconst out = parse(f);\n```\n\n### Iterator\n\nLike parse, but you get each row at a time so you can stop early.\n\n```js\nimport { iter } from 'but-csv';\n\nfor (const row of iter('foo,bar,zing\\n1,2,3\\n4,5')) {\n  // row will be an array of:\n  // 1. ['foo', 'bar', 'zing'],\n  // 2. ['1', '2', '3']\n  // 3. ['4','5']\n}\n```\n\n### Build\n\nYou can pass any value and it will be stringified before render, useful for numbers.\nThis is unlike the parser above, which only returns strings.\n\n```js\nimport { build } from 'but-csv';\n\nconst out = build([\n  ['hello', 'there\"\\n'],\n  [1, 2],\n]);\n\n// out will be:\n// hello,\"there\"\"\n// \"\n// 1,2\n```\n\n## Advanced\n\nBe sure to turn on your bundler's tree-shaking ability (good practice in general), but especially if you're only parsing _or_ building, because the code is separate.\nParsing is about 75% of the code, and building 25%.\n\n## Speed\n\nIt's very fast, but doesn't support streaming.\nTo parse multiple copies of [1.csv](https://github.com/Keyang/csvbench/blob/master/1.csv) from here, parsing all at once:\n\n```\nbut-csv: 732.908ms\npapaparse: 1.337s (1.8x)\ncsv-parser: 2.283s (3.1x)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamthor%2Fbut-csv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamthor%2Fbut-csv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamthor%2Fbut-csv/lists"}