Skip to content

Commit

Permalink
bugfix:number string confusing
Browse files Browse the repository at this point in the history
  • Loading branch information
zk-luke committed Oct 26, 2017
1 parent 40e8a24 commit 05459eb
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lib/xlsx-to-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,20 @@ function parseRow(row, rowIndex, head) {

switch (type) {
case 'id': // number string boolean
result[name] = cell;
if (isNumber(cell)) {
result[name] = Number(cell);
} else {
result[name] = cell;
}
break;
case 'basic': // number string boolean
result[name] = cell;
if (isNumber(cell)) {
result[name] = Number(cell);
} else if (isBoolean(cell)) {
result[name] = toBoolean(cell);
} else {
result[name] = cell;
}
break;
case 'date':
if (isDateType(cell)) {
Expand All @@ -139,19 +149,18 @@ function parseRow(row, rowIndex, head) {
}
break;
case 'string':
result[name] = cell;
result[name] = cell.toString();
break;
case 'number':
//+xxx.toString() '+' means convert it to number
let isNumber = !isNaN(+cell.toString());
if (isNumber) {
if (isNumber(cell)) {
result[name] = Number(cell);
} else {
console.warn("type error at [" + rowIndex + "," + index + "]," + cell + " is not a number");
}
break;
case 'bool':
result[name] = toBoolean(cell.toString());
result[name] = toBoolean(cell);
break;
case '{}': //support {number boolean string date} property type
result[name] = array2object(cell.split(';'));
Expand All @@ -163,7 +172,7 @@ function parseRow(row, rowIndex, head) {
result[name] = parseObjectArrayField(cell);
break;
default:
console.log('unrecognized type','['+ rowIndex +','+ index +']', cell, typeof(cell));
console.log('unrecognized type', '[' + rowIndex + ',' + index + ']', cell, typeof(cell));
break;
}
}
Expand Down

0 comments on commit 05459eb

Please sign in to comment.