CSV Stringifier
Input objects or Arrays and output texts
This package is a stringifier converting records into a CSV text and implementing the Node.js stream.Transform API. It is also providing a simple callback-base API for converniency. It is both extremely easy to use and powerfull. It was released since 2010 and is tested against very large dataset by a large community.
Source code for this project is available on GitHub.
使用
Run npm install csv
to install the full csv module or run npm install csv-stringify
if you are only interested by the CSV stringifier.
Use the callback style API for simplicity or the stream based API for scalability.
回调
stringify(data, [options], callback)
流
stringify([options], [callback])
For additionnal usage and example, you may refer to example page, the "samples" folder and the "test" folder.
选项
选项包括:
columns
List of fields, applied when transform returns an object, order matters, read the transformer documentation for additionnal information, columns are auto discovered in the first record when the user write objects, see the "header" option on how to print columns names on the first line.
delimiter
Set the field delimiter, one character only, defaults to a comma.
eof
Add the value of "options.rowDelimiter" on the last line, default to true.
escape
Defaults to the escape read option.
header
Display the column names on the first line if the columns option is provided or discovered.
quote
Defaults to the quote read option.
quoted
Boolean, default to false, quote all the non-empty fields even if not required.
quotedEmpty
Boolean, no default, quote empty fields? If specified, overrides quotedString for empty strings.
quotedString
Boolean, default to false, quote all fields of type string even if not required.
rowDelimiter
String used to delimit record rows or a special value; special values are 'auto', 'unix', 'mac', 'windows', 'unicode'; defaults to 'auto' (discovered in source or 'unix' if no source is specified).
所有选项都可选.