vlucas/sheetquery

Update not putting numeric Zero (0)

Dmytro2V opened this issue · 1 comments

Hi!
Probably a bug.

Description:
If there is numeric 0 to update, we receive "" instead in a cell.

Cause:
There is 2 places making this distortion:
1)
in updateRow(row, updateFn) function there is

const arrayValues = headings.map((heading) => {
      return (heading && updatedRow[heading]) || (heading && updatedRow[heading] === false)
        ? updatedRow[heading]
        : '';
});

code.
If updatedRow[heading] === 0 then heading && updatedRow[heading] returns 0 numeric. So 0 === false is not working as expected.

  1. in same function
const newValues = rangeData.map((value, index) => {
      return arrayValues[index] || value;
});

causes to return old value insted new, if new is 0.

Solution:
Need something like
1 ) Boolean(heading && updatedRow[heading]) === false
2) return arrayValues[index] ?? value;

PS :
Same in insert function

vlucas commented

Your PR #12 fixes this, so I am closing this issue ticket.