-
Notifications
You must be signed in to change notification settings - Fork 1
Support for string and numbers in isValidNumber function #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jesusrodrz @GerardoAGL96 me parece que isValidString
debe forzar a recibir un numero, y quizas un rango seria util tambien.
Me parece que el proceso de convertir un dato de un tipo a otro (normalizacion) debe ser manejado aparte. En todo caso, si queremos tener algo asi como utilitario, podemos hacerlo de una manera mas especifica:
isStringAValidNumber
que reciba un string, y por debajo use isValidNumber o algo asi.
Ref: https://gomakethings.com/converting-strings-to-numbers-with-vanilla-javascript/
@alacret I added the |
* @param {boolean} [allowZero=false] - If the string should accept 0 as a valid number. | ||
* @param {boolean} [allowNegative=false] - If the string should negative values. | ||
* | ||
* @returns {boolean} If the string is valid number or not. | ||
*/ | ||
export const isValidNumber = (stringToTest: string, allowZero: boolean = false, allowNegative: boolean = false): boolean => { | ||
export const isValidNumber = (value: string, allowZero: boolean = false, allowNegative: boolean = false): boolean => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const isValidNumber = (value: string, allowZero: boolean = false, allowNegative: boolean = false): boolean => { | |
export const isValidNumber = (value: number, allowZero: boolean = false, allowNegative: boolean = false): boolean => { | |
if(!typeof number !== "number") return false; |
Support for string and number values in isValidNumber function