All Projects → jimm → csvlixir

jimm / csvlixir

Licence: other
A CSV reading/writing application for Elixir.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to csvlixir

CsvTextFieldParser
A simple CSV parser based on Microsoft.VisualBasic.FileIO.TextFieldParser.
Stars: ✭ 40 (+25%)
Mutual labels:  csv, csv-reading, csv-parser
React Papaparse
react-papaparse is the fastest in-browser CSV (or delimited text) parser for React. It is full of useful features such as CSVReader, CSVDownloader, readString, jsonToCSV, readRemoteFile, ... etc.
Stars: ✭ 116 (+262.5%)
Mutual labels:  csv, csv-parser
flextures
This plug-in can load and dump test data in databases, loading function is very flexible, dump function is very simple
Stars: ✭ 21 (-34.37%)
Mutual labels:  csv-export, csv-import
Node Csvtojson
Blazing fast and Comprehensive CSV Parser for Node.JS / Browser / Command Line.
Stars: ✭ 1,760 (+5400%)
Mutual labels:  csv, csv-data
Windmill
A library to parse or write Excel and CSV files through a fluent API
Stars: ✭ 19 (-40.62%)
Mutual labels:  csv-parser, csv-export
Csv Stream
📃 Streaming CSV Parser for Node. Small and made entirely out of streams.
Stars: ✭ 98 (+206.25%)
Mutual labels:  csv, csv-parser
Dataclass Csv
Map CSV to Data Classes
Stars: ✭ 133 (+315.63%)
Mutual labels:  csv, csv-parser
Csv
Fast C# CSV parser
Stars: ✭ 53 (+65.63%)
Mutual labels:  csv, csv-parser
Csv2
Fast CSV parser and writer for Modern C++
Stars: ✭ 164 (+412.5%)
Mutual labels:  csv, csv-parser
comma splice
Fixes CSVs with unquoted commas in values
Stars: ✭ 67 (+109.38%)
Mutual labels:  csv-reading, csv-parser
Cursively
A CSV reader for .NET. Fast, RFC 4180 compliant, and fault tolerant. UTF-8 only.
Stars: ✭ 34 (+6.25%)
Mutual labels:  csv-reading, csv-parser
Csv Parser
Fast, header-only, extensively tested, C++11 CSV parser
Stars: ✭ 90 (+181.25%)
Mutual labels:  csv, csv-parser
Ngx Papaparse
Papa Parse wrapper for Angular
Stars: ✭ 83 (+159.38%)
Mutual labels:  csv, csv-parser
Papaparse
Fast and powerful CSV (delimited text) parser that gracefully handles large files and malformed input
Stars: ✭ 10,206 (+31793.75%)
Mutual labels:  csv, csv-parser
Csv File Validator
🔧🔦 Validation of CSV file against user defined schema (returns back object with data and invalid messages)
Stars: ✭ 60 (+87.5%)
Mutual labels:  csv, csv-parser
Etl.net
Mass processing data with a complete ETL for .net developers
Stars: ✭ 129 (+303.13%)
Mutual labels:  csv, csv-parser
Codablecsv
Read and write CSV files row-by-row or through Swift's Codable interface.
Stars: ✭ 214 (+568.75%)
Mutual labels:  csv, csv-parser
Fast Csv
CSV parser and formatter for node
Stars: ✭ 1,054 (+3193.75%)
Mutual labels:  csv, csv-parser
Faster Than Csv
Faster CSV on Python 3
Stars: ✭ 52 (+62.5%)
Mutual labels:  csv, csv-parser
React Csv Reader
React component that handles csv file input and its parsing
Stars: ✭ 138 (+331.25%)
Mutual labels:  csv, csv-parser

CSVLixir

A CSV reader/writer for Elixir. Operates on files or strings.

Installation

Add CSVLixir to your mix.exs dependencies:

def deps do
  [{:csvlixir, "~> 2.0.3"}]
end

Run mix deps.get. Done.

Reading

Files

To read CSV data from a file, use CSVLixir.read. It takes a path to a file and returns a Stream that generates and returns rows of CSV data.

CSVLixir.read("path/to/my.csv") |> Enum.to_list
#=> [["row", "one"], ["row", "two"]]

Strings

Parsing CSV data from a string returns a list of lists. Use CSVLixir.parse.

CSVLixir.parse("abc,def,ghi\n123,456,789")
#=> [["abc","def","ghi"],["123","456","789"]]

CSVLixir.parse(~s{abc,def,"gh"",""i"})
#=> [["abc", "def", "gh\",\"i"]]

CSVLixir.parse(File.read!("/tmp/foo.csv"))
#=> [["row", "one"], ["row", "two"]]

Writing

CSVLixir.write transforms a possibly lazy list of lists into a stream of CSV strings. Each generated string ends with a newline.

CSVLixir.write([["first", "row"], [123, 456]]) |> Enum.to_list
#=> ["first,row\n", "123,456\n"]

CSVLixir.write([["abc", "def", "gh\",\"i"], [123, 456, 789]])
|> Enum.each(&IO.write/1)
#=> abc,def,"gh"",""i"
#=> 123,456,789
#=> :ok

CSVLixir.write_row takes a single list and returns a single string.

CSVLixir.write_row(["a", "b", "c"])
#=> "a,b,c\n"

Writing to a file

Writing using streams:

f = File.open!("/tmp/csvlixir.csv", [:write])
1..3
|> Stream.map(&([&1, &1+1 ,&1+2]))
|> CSVLixir.write
|> Stream.each(&(IO.write(f, &1)))
|> Stream.run
File.close(f)

File.read!("/tmp/csvlixir.csv")
# => "1,2,3\n2,3,4\n3,4,5\n"

Writing a line at a time:

f = File.open!("/tmp/csvlixir.csv", [:write, :utf8])
IO.write(f, CSVLixir.write_row(["garçon", "waiter"]))
IO.write(f, CSVLixir.write_row(["résumé", "resume"]))
File.close(f)

File.read!("/tmp/csvlixir.csv")
# => "garçon,waiter\nrésumé,resume\n"

Don't forget to specify :utf8 when opening the file for writing if needed. (I often forget.)

Changes from 1.0

Adds reading from/writing to files. Removes support for char lists.

To Do

  • Allow different separator characters besides comma.
  • Handle headers. Return map instead of list, perhaps?
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].