xa3.csv

Another CSV format library for Haxe. Access content by Map
https://github.com/0xA3/xa3.csv

To install, run:

haxelib install xa3.csv 0.3.0 

See using Haxelib in Haxelib documentation for more information.

README.md

A CSV format library

Converts csv data to an easy to use format. Uses very simple parser for csv files. Autodetects delimiter: Space, Semikolon or Tab. For more complex csv files optionally uses https://github.com/jonasmalacofilho/csv library for parsing.

Simple Example

class Main {
	
	static function main() {
		
		// let's create some data to play with
		final header = "name;year;gender;favorite color";
		final line1 = "Lisa;1981;f;pink";
		final line2 = "Ben;1983;m;blue";
		final line3 = "Sofia;1988;f;orange";
		// and join it to a text string like it would be in a real csv file
		final s = [header, line1, line2, line3].join("\n");

		final csv = xa3.Csv.fromString( "Children grades", s );

		trace( 'The name of the csv is "${csv.name}""' );
		trace( 'ColumnNames are ${csv.columnNames}' );
		
		final favoriteColors = csv.lines.map( line -> line["favorite color"] ).join( "," );
		trace( 'The favorite colors of the children are $favoriteColors' );

	}
}

Complex Example

In this example the delimiter for the cells is a comma and there are also commas in the quotes. Because of this the parsing has to be done with the format.csv.Reader library and the resulting "csvRecords" are then converted to xa3.Csv.

class Main {
	
	static function main() {
		
		// let's create some data to play with
		final header = '"name","favorite quote"';
		final line1 = '"Lisa","Never mind what your friend said, if you wanna have fun with your girl try dancing"';
		final line2 = '"Ben","Well, duh shes rachet."';
		final line3 = '"Sofia","Here, take some tums!"';
		// and join it to a text string like it would be in a real csv file
		final s = [header, line1, line2, line3].join("\n");

		final csvRecords = format.csv.Reader.parseCsv( s );
		final csv = xa3.Csv.fromCsvRecords( csvRecords, "Favorite quotes" );

		trace( 'The name of the csv is "${csv.name}""' );
		trace( 'ColumnNames are ${csv.columnNames}' );
		
		final favoriteColors = csv.lines.map( line -> line["favorite quote"] ).map( quote -> '"$quote"' ).join( "," );
		trace( 'The favorite quotes of the children are $favoriteColors' );

	}
}

Issues

Found any bug? Please create a new issue.

Contributors
0xA3
Version
0.3.0
Published
1 year ago
Dependencies
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub