(opts)
| 3 | import { underscore } from "../utils/underscore.js"; |
| 4 | |
| 5 | const normalize_options = function (opts) { |
| 6 | const options = {}; |
| 7 | // Merge with user options |
| 8 | for (const opt in opts) { |
| 9 | options[underscore(opt)] = opts[opt]; |
| 10 | } |
| 11 | // Normalize option `bom` |
| 12 | if ( |
| 13 | options.bom === undefined || |
| 14 | options.bom === null || |
| 15 | options.bom === false |
| 16 | ) { |
| 17 | options.bom = false; |
| 18 | } else if (options.bom !== true) { |
| 19 | return [ |
| 20 | new CsvError("CSV_OPTION_BOOLEAN_INVALID_TYPE", [ |
| 21 | "option `bom` is optional and must be a boolean value,", |
| 22 | `got ${JSON.stringify(options.bom)}`, |
| 23 | ]), |
| 24 | ]; |
| 25 | } |
| 26 | // Normalize option `delimiter` |
| 27 | if (options.delimiter === undefined || options.delimiter === null) { |
| 28 | options.delimiter = ","; |
| 29 | } else if (Buffer.isBuffer(options.delimiter)) { |
| 30 | options.delimiter = options.delimiter.toString(); |
| 31 | } else if (typeof options.delimiter !== "string") { |
| 32 | return [ |
| 33 | new CsvError("CSV_OPTION_DELIMITER_INVALID_TYPE", [ |
| 34 | "option `delimiter` must be a buffer or a string,", |
| 35 | `got ${JSON.stringify(options.delimiter)}`, |
| 36 | ]), |
| 37 | ]; |
| 38 | } |
| 39 | // Normalize option `quote` |
| 40 | if (options.quote === undefined || options.quote === null) { |
| 41 | options.quote = '"'; |
| 42 | } else if (options.quote === true) { |
| 43 | options.quote = '"'; |
| 44 | } else if (options.quote === false) { |
| 45 | options.quote = ""; |
| 46 | } else if (Buffer.isBuffer(options.quote)) { |
| 47 | options.quote = options.quote.toString(); |
| 48 | } else if (typeof options.quote !== "string") { |
| 49 | return [ |
| 50 | new CsvError("CSV_OPTION_QUOTE_INVALID_TYPE", [ |
| 51 | "option `quote` must be a boolean, a buffer or a string,", |
| 52 | `got ${JSON.stringify(options.quote)}`, |
| 53 | ]), |
| 54 | ]; |
| 55 | } |
| 56 | // Normalize option `quoted` |
| 57 | if (options.quoted === undefined || options.quoted === null) { |
| 58 | options.quoted = false; |
| 59 | } else { |
| 60 | // todo |
| 61 | } |
| 62 | // Normalize option `escape_formulas` |
no test coverage detected