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$/, "");
},
Method csv
Parameters:
arg must be a String.
(JSON string to transform)
delimiter must be a String.
([Optional] Character to separate fields)
header must be a Boolean.
([Optional] False to not include field names as first row)
Returns a String
(CSV string)