@@ -11,6 +11,17 @@ var json2Csv = require('./json-2-csv'), // Require our json-2-csv code
1111 */
1212var 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
0 commit comments