You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the old inquirer there was a Number input, Im trying to do something similar with the new @inquirer/prompts and wonder if there is a way to cast the value before it gets to the validate method. Any idea?
I know I can do the cast after calling await input but:
I think it is nicer to have all the input-related code in one place (the input options)
Currently the validate method gets a string and I need to "parse" it there as well.
Thx.
The text was updated successfully, but these errors were encountered:
Hey, I'm not against re-adding a good number prompt if you want to send a PR! I didn't reimplement as I found the previous UX bad, and didn't care much about it.
With the input prompt, for now I would do something:
constanswer=parseInt(awaitinput({message: 'Provide a number:',validate: (value)=>!Number.isNaN(value)||'You must provide a number',}),10,);
Yes, workarounds are possible but less nicer than the old number prompt.
My validate really needs a number to check it is within range etc. I know it's still doable but...
I wonder whether a "cast"/"filter" method would be a better addition to the api, that way if someone wants a number he may cast the string to number, if someone wants a date she may cast the string to date, all before the validate stage, and the result would also be the result of the "cast".
In the old
inquirer
there was a Number input, Im trying to do something similar with the new@inquirer/prompts
and wonder if there is a way to cast the value before it gets to thevalidate
method. Any idea?I know I can do the cast after calling
await input
but:validate
method gets a string and I need to "parse" it there as well.Thx.
The text was updated successfully, but these errors were encountered: