Skip to content
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

Adds a NumberPrompt type for convenience (#654) #663

Merged
merged 1 commit into from May 14, 2018

Conversation

CaAlden
Copy link
Contributor

@CaAlden CaAlden commented Apr 5, 2018

Creates a convenient prompt specifically for getting numbers as input from the user. If the user input's something that is not a number, a default value is returned if it exists or NaN if no default was specified.

@SBoudrias
Copy link
Owner

Thanks!

if (input && typeof input === 'string') {
input = input.trim();
// Match a number in the input
let numberMatch = input.match(/(^-?\d+|^\d+\.\d*|^\d*\.\d+)(e\d+)?$/);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this better than parseFloat in some way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants