Skip to content

Commit

Permalink
Tidy code
Browse files Browse the repository at this point in the history
  • Loading branch information
matttdawson committed Jun 21, 2023
1 parent f3cd335 commit bd6a1c1
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ export const wait = (timeoutMs: number) =>
const isFloatRegExp = /^-?\d*\.?\d*$/;
export const isFloat = (value: string) => {
try {
if (Number.isNaN(parseFloat(value))) {
return false;
}
// Just checking it's not scientific notation here.
// Just checking it's not scientific notation or "NaN" here.
// Also parse float will parse up to the first invalid character,
// so we need to check there's no remaining invalids e.g. "1.2xyz" would parse as 1.2
return isFloatRegExp.test(value);
return !Number.isNaN(parseFloat(value)) && isFloatRegExp.test(value);
} catch {
return false;
}
Expand Down

0 comments on commit bd6a1c1

Please sign in to comment.