CSV Stringify options
All options are optional. All the options from the Node.js Writable Stream API and the Node.js Readable Stream API are supported and passed as is.
Available options
-
cast
Defines custom cast for certain data types; wasformatters
until version 4.3.1.boolean
Custom function to transform boolean values.date
Custom function to transform date values.number
Custom function to transform number values.object
Custom function to transform object literals.
columns
(array|object)
List of properties when records are provided as objects; work with records in the form of arrays based on index position; order matters; auto discovered in the first record when the user write objects, can refer to nested properties of the input JSON, see the "header" option on how to print columns names on the first line.delimiter
(string)
Set the field delimiter, one or multiple characters, defaults to a comma.eof
Add the value of "options.rowDelimiter" on the last line, default to true.escape
(string|Buffer)
Single character used for escaping; only apply to characters matching thequote
and theescape
options default to"
.header
(boolean)
Display the column names on the first line if the columns option is provided or discovered.quote
(string|Buffer|boolean)
The quote characters, defaults to the"
, an empty quote value will preserve the original field.quoted
(boolean)
Boolean, default to false, quote all the non-empty fields even if not required.quoted_empty
(boolean)
Quote empty strings and overridesquoted_string
on empty strings when defined; default isfalse
.quoted_match
(String|RegExp)
Quote all fields matching a regular expression; default isfalse
.quoted_string
(boolean)
Quote all fields of type string even if not required; default isfalse
.record_delimiter
(string|Buffer)
String used to delimit record rows or a special value; special values are 'auto', 'unix', 'mac', 'windows', 'ascii', 'unicode'; defaults to 'auto' (discovered in source or 'unix' if no source is specified); wasrowDelimiter
until version 4.3.1.
Choose your style
The code uses snake case as the conventional style for function and variable names. In snake case, all letters are lowercase and underscores separate words. It is however accepted to provide options in camel case. Thus, record_delimiter
and recordDelimiter
are equivalent when initialising a new instance of stringify
. The option will be converted into snake case and exposed as such. For example, in case you need to access the record_delimiter
option, use generate().options.record_delimiter
and not generate().options.recordDelimiter
. Choose the case which best fit your coding style.