MCPcopy Index your code
hub / github.com/adaltas/node-csv / normalize_options

Function normalize_options

packages/csv-parse/lib/api/normalize_options.js:6–760  ·  view source on GitHub ↗
(opts)

Source from the content-addressed store, hash-verified

4import { is_object } from "../utils/is_object.js";
5
6const normalize_options = function (opts) {
7 const options = {};
8 // Merge with user options
9 for (const opt in opts) {
10 options[underscore(opt)] = opts[opt];
11 }
12 // Normalize option `encoding`
13 // Note: defined first because other options depends on it
14 // to convert chars/strings into buffers.
15 if (options.encoding === undefined || options.encoding === true) {
16 options.encoding = "utf8";
17 } else if (options.encoding === null || options.encoding === false) {
18 options.encoding = null;
19 } else if (
20 typeof options.encoding !== "string" &&
21 options.encoding !== null
22 ) {
23 throw new CsvError(
24 "CSV_INVALID_OPTION_ENCODING",
25 [
26 "Invalid option encoding:",
27 "encoding must be a string or null to return a buffer,",
28 `got ${JSON.stringify(options.encoding)}`,
29 ],
30 options,
31 );
32 }
33 // Normalize option `bom`
34 if (
35 options.bom === undefined ||
36 options.bom === null ||
37 options.bom === false
38 ) {
39 options.bom = false;
40 } else if (options.bom !== true) {
41 throw new CsvError(
42 "CSV_INVALID_OPTION_BOM",
43 [
44 "Invalid option bom:",
45 "bom must be true,",
46 `got ${JSON.stringify(options.bom)}`,
47 ],
48 options,
49 );
50 }
51 // Normalize option `cast`
52 options.cast_function = null;
53 if (
54 options.cast === undefined ||
55 options.cast === null ||
56 options.cast === false ||
57 options.cast === ""
58 ) {
59 options.cast = undefined;
60 } else if (typeof options.cast === "function") {
61 options.cast_function = options.cast;
62 options.cast = true;
63 } else if (options.cast !== true) {

Callers 8

delimiter_discoverFunction · 0.90
transformFunction · 0.90
option.from.tsFile · 0.90
api.types.tsFile · 0.90
api.error.tsFile · 0.90

Calls 4

underscoreFunction · 0.90
normalize_columns_arrayFunction · 0.90
is_objectFunction · 0.90
toStringMethod · 0.80

Tested by

no test coverage detected