Skip to content

Commit

Permalink
chore(validate): coerce numbers from strings
Browse files Browse the repository at this point in the history
  • Loading branch information
gadicc committed Feb 6, 2021
1 parent 4b19ca1 commit 89812b3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib/validateAndCoerceTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ ajv.addKeyword({
if (typeof data === 'number')
return true;

if (typeof data === 'string') {
let float = Number.parseFloat(data);
if (Number.isNaN(float))
return false;
return set(float);
}

if (typeof data === 'object') {
if (Object.keys(data).length === 0)
return set(null);
Expand Down

0 comments on commit 89812b3

Please sign in to comment.