CSVStringify for Node.js

IssuesGitHub

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

  • bom (boolean)
    Since version 5.4.0
    Prepend the byte order mark (BOM) to the output stream.
  • cast
    Since version 1.1.0
    Defines custom cast for certain data types; was formatters until version 4.3.1.
    • bigint Custom function to transform bigint values.
    • 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.
    • string Custom function to transform string values.
  • columns (array|object)
    Since version 0.0.1
    Influence the generation of records at the field level.
  • delimiter (string)
    Since version 0.0.1
    Set the field delimiter, one or multiple characters, defaults to a comma.
  • eof (boolean)
    Since version 0.0.2
    Append the value of the record_delimiter option after the last record, default to true.
  • escape (string|Buffer)
    Since version 0.0.1
    Single character used for escaping; only apply to characters matching the quote and the escape options default to ".
  • escape_formulas (boolean)
    Since version 6.3.0
    Escape values that start with =, +, -, @, \t, or \r with ' and defend against CSV injection attacks.
  • header (boolean)
    Since version 0.0.1
    Display the column names on the first line if the columns option is provided or discovered.
  • quote (string|Buffer|boolean)
    Since version 0.0.1
    The quote characters surrounding a field, defaults to the " (double quotation marks), an empty quote value will preserve the original field, whether it contains quotation marks or not.
  • quoted (boolean)
    Since version 0.0.1
    Boolean, default to false, quote all the non-empty fields even if not required.
  • quoted_empty (boolean)
    Since version 5.1.0
    Quote empty strings and overrides quoted_string on empty strings when defined; default is false.
  • quoted_match (String|RegExp)
    Since version 5.1.0
    Quote all fields matching a regular expression; default is false.
  • quoted_string (boolean)
    Since version 5.1.0
    Quote all fields of type string even if not required; default is false.
  • record_delimiter (string|Buffer)
    Since version 0.0.1
    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); was rowDelimiter 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.

About

The Node.js CSV project is an open source product hosted on GitHub and developed by Adaltas.