Skip to content

Commit d7b02ab

Browse files
committed
feat: add in auto detect of newline * delimiters
1 parent 2e5ab3e commit d7b02ab

File tree

5 files changed

+1301
-376
lines changed

5 files changed

+1301
-376
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,19 @@ const csv = format(linesArray, {})
6666

6767
## Options
6868

69-
### Common
70-
- `newlineChar` (`\r\n`): What `newline` character(s) to be used.
71-
- `delimiterChar` (`,`): Characters used to separate fields. Must be length of 1
72-
- `quoteChar` (`"`): Character used to wrap fields that need to have special characters within them. Must be length of 1
73-
- `escapeChar` (`${quoteChar}`): Character used to escape the `quoteChar`. Must be length of 1
74-
7569
### Parse
7670
- `header` (`true`): Keys to be used in JSON object for the parsed row
7771
- `true`: First row of the `input` is the headers and will need to be pulled out
7872
- `[...]`: Pre-assign headers because `input` contains no headers.
7973
- `false`: Don't map to JSON, return array of values instead.
74+
- `newlineChar` (`''`): What `newline` character(s) to be used. By default will guess from `\r\n`, `\n`, `\r`
75+
- `delimiterChar` (`''`): Characters used to separate fields. Must be length of 1. By default will guess from `,`, `\t`, `|`, `;`, `\x1E`, `\x1F`
76+
- `quoteChar` (`"`): Character used to wrap fields that need to have special characters within them. Must be length of 1
77+
- `escapeChar` (`${quoteChar}`): Character used to escape the `quoteChar`. Must be length of 1
8078
- `enqueue` (`({data, idx, err}) => {}`): Function to run on parsed row data.
81-
- `emptyFieldValue` (``): Value to be used instead of an empty string. Can be set to `undefined` to have empty fields not be included.
82-
- `coerceField` (`(field) => field`): Function to apply type/value coercion.
83-
- `commentPrefixValue` (false): Lines starting with this value will be ignored (i.e. `#`, `//`). Can be set to `false` if files will never have comments.
79+
- `emptyFieldValue` (`''`): Value to be used instead of an empty string. Can be set to `undefined` to have empty fields not be included.
80+
- `coerceField` (`(field, idx) => field`): Function to apply type/value coercion.
81+
- `commentPrefixValue` (`false`): Lines starting with this value will be ignored (i.e. `#`, `//`). Can be set to `false` if files will never have comments.
8482
- `errorOnEmptyLine` (`true`): When an empty line is encountered. Push row with error when occurs, row ignored otherwise.
8583
- `errorOnComment` (`true`): When a comment is encountered. Push row with error when occurs, row ignored otherwise.
8684
- `errorOnFieldsMismatch` (`true`): When number of headers does not match the number of fields in a row. Push row with error when occurs, row ignored otherwise.
@@ -93,6 +91,10 @@ const csv = format(linesArray, {})
9391
- `true`: Will create header from `Object.keys()`
9492
- `[...]`: Pre-assign headers to be included from object.
9593
- `false`: will not include a header line. Will use `Object.values()` for rows
94+
- `newlineChar` (`\r\n`): What `newline` character(s) to be used.
95+
- `delimiterChar` (`,`): Characters used to separate fields.
96+
- `quoteChar` (`"`): Character used to wrap fields that need to have special characters within them.
97+
- `escapeChar` (`${quoteChar}`): Character used to escape the `quoteChar`.
9698
- `quoteColumn`: (`undefined`): Array that maps to the headers to indicate what columns need to have quotes. Used to improve performance.
9799
- `true`: Always quote column
98100
- `false`: Never quote column

0 commit comments

Comments
 (0)