MCPcopy
hub / github.com/adaltas/node-csv / normalize_options

Function normalize_options

packages/csv-stringify/lib/api/normalize_options.js:5–277  ·  view source on GitHub ↗
(opts)

Source from the content-addressed store, hash-verified

3import { underscore } from "../utils/underscore.js";
4
5const 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`

Callers 3

constructorMethod · 0.90
stringifyFunction · 0.90
stringifierFunction · 0.90

Calls 3

underscoreFunction · 0.90
normalize_columnsFunction · 0.90
toStringMethod · 0.80

Tested by

no test coverage detected