lib/abaaso.js
function ( arg, delimiter, header ) {
		delimiter  = delimiter || ",";
		header     = ( header !== false );
		var obj    = json.decode( arg, true ) || arg,
		    result = "",
		    prepare;

		// Prepares input based on CSV rules
		prepare = function ( input ) {
			var output;

			if ( input instanceof Array ) {
				output = "\"" + input.toString() + "\"";

				if ( regex.object_type.test( output ) ) {
					output = "\"" + json.csv( input, delimiter ) + "\"";
				}
			}
			else if ( input instanceof Object ) {
				output = "\"" + json.csv( input, delimiter ) + "\"";
			}
			else if ( regex.csv_quote.test( input ) ) {
				output = "\"" + input.replace( /"/g, "\"\"" ) + "\"";
			}
			else {
				output = input;
			}

			return output;
		};

		if ( obj instanceof Array ) {
			if ( obj[0] instanceof Object ) {
				if ( header ) {
					result = ( array.keys( obj[0] ).join( delimiter ) + "\n" );
				}

				result += obj.map( function ( i ) {
					return json.csv( i, delimiter, false );
				}).join( "\n" );
			}
			else {
				result += ( prepare( obj, delimiter ) + "\n" );
			}

		}
		else {
			if ( header ) {
				result = ( array.keys( obj ).join( delimiter ) + "\n" );
			}

			result += ( array.cast( obj ).map( prepare ).join( delimiter ) + "\n" );
		}

		return result.replace(/\n$/, "");
	}
function ( arg, delimiter, header ) {
		delimiter  = delimiter || ",";
		header     = ( header !== false );
		var obj    = json.decode( arg, true ) || arg,
		    result = "",
		    prepare;

		// Prepares input based on CSV rules
		prepare = function ( input ) {
			var output;

			if ( input instanceof Array ) {
				output = "\"" + input.toString() + "\"";

				if ( regex.object_type.test( output ) ) {
					output = "\"" + json.csv( input, delimiter ) + "\"";
				}
			}
			else if ( input instanceof Object ) {
				output = "\"" + json.csv( input, delimiter ) + "\"";
			}
			else if ( regex.csv_quote.test( input ) ) {
				output = "\"" + input.replace( /"/g, "\"\"" ) + "\"";
			}
			else {
				output = input;
			}

			return output;
		};

		if ( obj instanceof Array ) {
			if ( obj[0] instanceof Object ) {
				if ( header ) {
					result = ( array.keys( obj[0] ).join( delimiter ) + "\n" );
				}

				result += obj.map( function ( i ) {
					return json.csv( i, delimiter, false );
				}).join( "\n" );
			}
			else {
				result += ( prepare( obj, delimiter ) + "\n" );
			}

		}
		else {
			if ( header ) {
				result = ( array.keys( obj ).join( delimiter ) + "\n" );
			}

			result += ( array.cast( obj ).map( prepare ).join( delimiter ) + "\n" );
		}

		return result.replace(/\n$/, "");
	}
function ( arg , delimiter , header ) { delimiter = delimiter || "," ; header = ( header !== false ) ; var obj = json . decode ( arg , true ) || arg , result = "" , prepare ; // Prepares input based on CSV rules prepare = function ( input ) { var output ; if ( input instanceof Array ) { output = "\"" + input . toString ( ) + "\"" ; if ( regex . object_type . test ( output ) ) { output = "\"" + json . csv ( input , delimiter ) + "\"" ; } } else if ( input instanceof Object ) { output = "\"" + json . csv ( input , delimiter ) + "\"" ; } else if ( regex . csv_quote . test ( input ) ) { output = "\"" + input . replace ( / " / g , "\"\"" ) + "\"" ; } else { output = input ; } return output ; } ; if ( obj instanceof Array ) { if ( obj [ 0 ] instanceof Object ) { if ( header ) { result = ( array . keys ( obj [ 0 ] ) . join ( delimiter ) + "\n" ) ; } result += obj . map ( function ( i ) { return json . csv ( i , delimiter , false ) ; } ) . join ( "\n" ) ; } else { result += ( prepare ( obj , delimiter ) + "\n" ) ; } } else { if ( header ) { result = ( array . keys ( obj ) . join ( delimiter ) + "\n" ) ; } result += ( array . cast ( obj ) . map ( prepare ) . join ( delimiter ) + "\n" ) ; } return result . replace ( / \n$ / , "" ) ; }
Transforms JSON to CSV

@method csv
@param  {String}  arg JSON  string to transform
@param  {String}  delimiter [Optional] Character to separate fields
@param  {Boolean} header    [Optional] False to not include field names as first row
@return {String}            CSV string
Transforms JSON to CSV