Skip to content

Commit

Permalink
fix: Don't parse NaNs, but serialise them
Browse files Browse the repository at this point in the history
  • Loading branch information
franky47 committed Aug 31, 2023
1 parent 8a50113 commit 4da7786
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/lib/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,14 @@ export const queryTypes: QueryTypeMap = {
}
},
integer: {
parse: v => parseInt(v) || null,
serialize: v => {
if (isNaN(v)) return null;
return Math.round(v).toFixed();
parse: v => {
const int = parseInt(v)
if (Number.isNaN(int)) {
return null
}
return int
},
serialize: v => Math.round(v).toFixed(),
withDefault(defaultValue) {
return {
...this,
Expand All @@ -111,11 +114,14 @@ export const queryTypes: QueryTypeMap = {
}
},
float: {
parse: v => parseFloat(v) || null,
serialize: v => {
if (isNaN(v)) { return null }
return v.toString()
}
parse: v => {
const float = parseFloat(v)
if (Number.isNaN(float)) {
return null
}
return float
},
serialize: v => v.toString(),
withDefault(defaultValue) {
return {
...this,
Expand Down

0 comments on commit 4da7786

Please sign in to comment.