Skip to content

Commit 274059b

Browse files
committed
added log message when null/nil values are found
1 parent 4de2f9e commit 274059b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/modules/CSVModule.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,29 @@ const parse = require('csv-parse/lib/sync');
44
const logger = require('../helpers/logger');
55

66
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) => {
1011
const newRow = { ...row };
1112
// Filter out unalterable columns
1213
const columnsToNormalize = Object.keys(row).filter((col) => !unalterableColumns.includes(col));
1314
columnsToNormalize.forEach((col) => {
1415
const value = newRow[col];
1516
// If the value for this row-col combo is a value that should be empty, replace it
1617
if (EMPTY_VALUES.includes(value.toLowerCase())) {
18+
logger.debug(`NULL/NIL values '${value}' found in row-${i}, col-${col}`);
19+
wasNormalized = true;
1720
newRow[col] = '';
1821
}
1922
});
2023
return newRow;
2124
});
25+
26+
if (wasNormalized) {
27+
logger.warn('NULL/NIL values found and replaced with empty-strings');
28+
}
29+
return newData;
2230
}
2331

2432
class CSVModule {

0 commit comments

Comments
 (0)