GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - BoogeyCodes/tinycsv: A tiny zero-dependency RFC 4180 CSV parser and stringifier for TypeScript: quoted fields, escapes, custom delimiters, object mapping

BranchesTags
Open more actions menu

Latest commit

 

History

6 Commits
6 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
src
src
 
 
test
test
 
 
.gitignore
.gitignore
 
 
.npmignore
.npmignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 
tsup.config.ts
tsup.config.ts
 
 
vitest.config.ts
vitest.config.ts
 
 

Repository files navigation

tinycsv

CI TypeScript Zero dependencies ESM + CJS License: MIT

A tiny CSV parser and stringifier for TypeScript, with no dependencies. It follows RFC 4180, so quoted fields, escaped quotes, embedded commas and newlines all work — the cases a naive split(',') gets wrong.

import { parse, stringify, parseObjects } from 'tinycsv'

parse('name,note\n"Smith, John","line1\nline2"')
// [ ['name', 'note'], ['Smith, John', 'line1\nline2'] ]

parseObjects('id,name\n1,Alice\n2,Bob')
// [ { id: '1', name: 'Alice' }, { id: '2', name: 'Bob' } ]

stringify([['a', 'b'], ['has,comma', 'ok']])
// 'a,b\n"has,comma",ok'

Why

CSV looks trivial until a field contains a comma, a quote or a newline — then split(',') breaks, and reaching for a big library feels like overkill. tinycsv is the small, correct middle: a proper RFC 4180 state-machine parser and a matching stringifier that quotes only what needs quoting, round-trip safe, in a couple hundred lines with no dependencies.

Features

  • Parsing that handles quoted fields containing the delimiter, newlines and escaped quotes (""), with \n, \r\n and bare \r line endings.
  • Stringifying that quotes only the fields that need it (or all, on request), and renders null and undefined as empty.
  • Object mapping: parseObjects keys rows by a header row; stringifyObjects writes a header and rows, inferring columns or using an explicit order.
  • Options: custom delimiter (so it reads TSV too), quote, trim, skipEmptyLines, newline, quoteAll.
  • Round-trip safe: parse(stringify(rows)) returns the original data.

API

import { parse, parseObjects, stringify, stringifyObjects } from 'tinycsv'

// string[][]
parse(text, { delimiter: ',', quote: '"', trim: false, skipEmptyLines: true })

// Record<string, string>[]
parseObjects(text, options)

// string
stringify(rows, { delimiter: ',', quote: '"', newline: '\n', quoteAll: false })
stringifyObjects(records, { columns: ['a', 'b'], ...options })

Reading TSV

parse('a\tb\n1\t2', { delimiter: '\t' })   // [['a','b'], ['1','2']]

Testing

npm install
npm test            # 19 tests across parse, stringify and round-tripping
npm run build       # ESM + CJS + .d.ts via tsup

Tests cover quoted fields with commas and newlines, doubled-quote escapes, CRLF/CR endings, empty fields and lines, custom delimiters, trimming, trailing fields, object mapping, selective quoting, and a parse/stringify round trip. CI runs on Linux and Windows across Node 18/20/22.

Ideas for later

  • Streaming parse for very large files.
  • Type coercion hooks (numbers, booleans, dates).
  • A header-rename map.

License

MIT

About

A tiny zero-dependency RFC 4180 CSV parser and stringifier for TypeScript: quoted fields, escapes, custom delimiters, object mapping

Topics

csvparserrfc4180tsvtypescriptzero-dependency

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.