-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(checks): add isNumericInt/Float() checks
- Loading branch information
1 parent
af5d943
commit 7e054c1
Showing
2 changed files
with
17 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Returns true if given string contains only digits, and optionally, a sign | ||
* prefix. | ||
* | ||
* @param x | ||
*/ | ||
export const isNumericInt = (x: string) => /^[-+]?\d+$/.test(x); | ||
|
||
/** | ||
* Returns true if given string only contains an integer or floating point | ||
* number, optionally in scientific notiation (e.g. `-123.45e-6`). | ||
* | ||
* @param x | ||
*/ | ||
export const isNumericFloat = (x: string) => | ||
/^[-+]?\d*\.?\d+(e[-+]?\d+)?$/i.test(x); |