Skip to content

Commit

Permalink
fix(core): fix handling of generic best guesses
Browse files Browse the repository at this point in the history
  • Loading branch information
larsgw committed Aug 30, 2019
1 parent 50fa283 commit c8e8c78
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/core/src/plugins/input/csl.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,20 @@ const correctField = function (fieldName, value, bestGuessConversions) {
return correctDate(value, bestGuessConversions)
}

if (fieldType.includes(typeof value)) {
if (/^_/.test(fieldName)) {
return value
} else if (/^_/.test(fieldName)) {
} else if (bestGuessConversions) {
if (typeof value === 'string' && fieldType.includes('number') && !isNaN(+value)) {
return parseFloat(value)
} else if (typeof value === 'number' && fieldType.includes('string') && !fieldType.includes('number')) {
return value.toString()
} else if (Array.isArray(value) && value.length) {
return correctField(fieldName, value[0], bestGuessConversions)
}
}

if (fieldType.includes(typeof value)) {
return value
} else if (!bestGuessConversions) {
return undefined
} else if (typeof value === 'string' && fieldType.includes('number') && parseFloat(value)) {
return parseFloat(value)
} else if (typeof value === 'number' && fieldType.includes('string') && !fieldType.includes('number')) {
return value.toString()
} else if (Array.isArray(value) && value.length) {
return correctField(fieldName, value[0])
}
}

Expand Down

0 comments on commit c8e8c78

Please sign in to comment.