dumb-csv
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

dumb-csv

NPM version Build Status Try it on gitpod

An unfancy CSV to JSON/markdown parsing lib with no streams or asynchrony

Install

npm install dumb-csv

Usage

const dumbcsv = require('dumb-csv')
dumbcsv
  .fromCSV({ data: 'hello,world', separator: ',', headerFields: ['a', 'b'] })
  .toJSON()
// [{"a":"hello","b":"world"}]

API

fromCSV(options: { data, file, separator = ',', headerFields, overrideExistingHeader, parseFloats = true }) : { toJSON: () => object, toMarkdown: () => string }

Input options object:

  • data (string) -- a string representing the CSV data
  • OR file (string) -- a path to the CSV
  • headerFields (optional string[]) -- an array of strings containing the headers for the CSV, assuming they are not the 1st line
  • overrideExistingHeader (optional bool) -- if the 1st line IS a header, but your headerFields should override it
  • parseFloats (default true) -- if we should try and convert rows that are numbers into JS Number's, or if false keep everything as strings

Output object :

  • toJSON() (function) -- calling this will return a javascript object that represents the CSV
  • toMarkdown() (function) -- calling this will return a string that has a formatted markdown table inside that represents the CSV

Package Sidebar

Install

npm i dumb-csv

Weekly Downloads

17

Version

1.1.2

License

MIT

Unpacked Size

12.4 kB

Total Files

13

Last publish

Collaborators

  • extremeheat