Skip to content

Commit cd17a9d

Browse files
committed
Fixing multiple branches in converter
1 parent 9340cd8 commit cd17a9d

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

lib/converter.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ var json2Csv = require('./json-2-csv'), // Require our json-2-csv code
1111
*/
1212
var defaultOptions = constants.DefaultOptions;
1313

14+
var isDefined = function (val) {
15+
return !_.isUndefined(val);
16+
};
17+
18+
var copyOption = function (options, lowercasePath, uppercasePath) {
19+
var lowerCaseValue = docPath.evaluatePath(options, lowercasePath);
20+
if (isDefined(lowerCaseValue)) {
21+
docPath.setPath(options, uppercasePath, lowerCaseValue);
22+
}
23+
};
24+
1425
/**
1526
* Build the options to be passed to the appropriate function
1627
* If a user does not provide custom options, then we use our default
@@ -23,19 +34,18 @@ var buildOptions = function (opts, cb) {
2334

2435
// #62: Allow for lower case option names
2536
if (opts) {
26-
if (!_.isUndefined(opts.prependHeader)) { docPath.setPath(opts, 'PREPEND_HEADER', opts.prependHeader); }
27-
if (!_.isUndefined(opts.trimHeaderFields)) { docPath.setPath(opts, 'TRIM_HEADER_FIELDS', opts.trimHeaderFields); }
28-
if (!_.isUndefined(opts.trimFieldValues)) { docPath.setPath(opts, 'TRIM_FIELD_VALUES', opts.trimFieldValues); }
29-
if (!_.isUndefined(opts.sortHeader)) { docPath.setPath(opts, 'SORT_HEADER', opts.sortHeader); }
30-
if (!_.isUndefined(opts.parseCsvNumbers)) { docPath.setPath(opts, 'PARSE_CSV_NUMBERS', opts.parseCsvNumbers); }
31-
if (!_.isUndefined(opts.keys)) { docPath.setPath(opts, 'KEYS', opts.keys); }
32-
if (!_.isUndefined(opts.checkSchemaDifferences)) { docPath.setPath(opts, 'CHECK_SCHEMA_DIFFERENCES', opts.checkSchemaDifferences); }
33-
if (!_.isUndefined(opts.emptyFieldValue)) { docPath.setPath(opts, 'EMPTY_FIELD_VALUE', opts.emptyFieldValue); }
34-
if (!_.isUndefined(opts.delimiter)) {
35-
if (!_.isUndefined(opts.delimiter.field)) { docPath.setPath(opts, 'DELIMITER.FIELD', opts.delimiter.field); }
36-
if (!_.isUndefined(opts.delimiter.array)) { docPath.setPath(opts, 'DELIMITER.ARRAY', opts.delimiter.array); }
37-
if (!_.isUndefined(opts.delimiter.wrap)) { docPath.setPath(opts, 'DELIMITER.WRAP', opts.delimiter.wrap); }
38-
if (!_.isUndefined(opts.delimiter.eol)) { docPath.setPath(opts, 'DELIMITER.EOL', opts.delimiter.eol); }
37+
copyOption(opts, 'prependHeader', 'PREPEND_HEADER');
38+
copyOption(opts, 'trimHeaderFields', 'TRIM_HEADER_FIELDS');
39+
copyOption(opts, 'sortHeader', 'SORT_HEADER');
40+
copyOption(opts, 'parseCsvNumbers', 'PARSE_CSV_NUMBERS');
41+
copyOption(opts, 'keys', 'KEYS');
42+
copyOption(opts, 'checkSchemaDifferences', 'CHECK_SCHEMA_DIFFERENCES');
43+
copyOption(opts, 'emptyFieldValue', 'EMPTY_FIELD_VALUE');
44+
if (isDefined(opts.delimiter)) {
45+
copyOption(opts, 'delimiter.field', 'DELIMITER.FIELD');
46+
copyOption(opts, 'delimiter.array', 'DELIMITER.ARRAY');
47+
copyOption(opts, 'delimiterwrap', 'DELIMITER.WRAP');
48+
copyOption(opts, 'delimiter.eol', 'DELIMITER.EOL');
3949
}
4050
}
4151

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "mrodrig",
33
"name": "json-2-csv",
44
"description": "A JSON to CSV and CSV to JSON converter that natively supports sub-documents and auto-generates the CSV heading.",
5-
"version": "2.0.19",
5+
"version": "2.0.20",
66
"repository": {
77
"type": "git",
88
"url": "http://github.com/mrodrig/json-2-csv.git"

0 commit comments

Comments
 (0)