File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -4,21 +4,29 @@ const parse = require('csv-parse/lib/sync');
4
4
const logger = require ( '../helpers/logger' ) ;
5
5
6
6
function normalizeEmptyValues ( data , unalterableColumns = [ ] ) {
7
- const EMPTY_VALUES = [ 'null' , 'nil' ] ;
8
-
9
- return data . map ( ( row ) => {
7
+ const EMPTY_VALUES = [ 'null' , 'nil' ] . map ( ( v ) => v . toLowerCase ( ) ) ;
8
+ // Flag tracking if data was normalized or not.
9
+ let wasNormalized = false ;
10
+ const newData = data . map ( ( row , i ) => {
10
11
const newRow = { ...row } ;
11
12
// Filter out unalterable columns
12
13
const columnsToNormalize = Object . keys ( row ) . filter ( ( col ) => ! unalterableColumns . includes ( col ) ) ;
13
14
columnsToNormalize . forEach ( ( col ) => {
14
15
const value = newRow [ col ] ;
15
16
// If the value for this row-col combo is a value that should be empty, replace it
16
17
if ( EMPTY_VALUES . includes ( value . toLowerCase ( ) ) ) {
18
+ logger . debug ( `NULL/NIL values '${ value } ' found in row-${ i } , col-${ col } ` ) ;
19
+ wasNormalized = true ;
17
20
newRow [ col ] = '' ;
18
21
}
19
22
} ) ;
20
23
return newRow ;
21
24
} ) ;
25
+
26
+ if ( wasNormalized ) {
27
+ logger . warn ( 'NULL/NIL values found and replaced with empty-strings' ) ;
28
+ }
29
+ return newData ;
22
30
}
23
31
24
32
class CSVModule {
You can’t perform that action at this time.
0 commit comments