Validate that default value is string or numeric #45

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@alex-seville

Right now there is an implicit* validation done after the read (https://github.com/flatiron/prompt/blob/master/lib/prompt.js#L463), but I think it might be helpful to do an explicit validation beforehand.

  • implicit only because it's not strictly testing the default value, unless the default is being returned
@indexzero
a decoupled application framework member

@alex-seville typeof defaultLine !== 'numeric' is not valid javascript. I believe you want typeof defaultLine !== 'number'

@alex-seville
@alex-seville alex-seville Validate that default value is string or numeric. Ignore otherwise.
Fixed typo

wrote numeric instead of number

If default is not string, try casting it

Number gets ignored on the way back anyway, so it's best to string converting it to a string
3c3c731
@alex-seville

I made a mess of the commits, so I squashed them.

I also noticed that number values would be ignored after reading by the same code on L463, so I modified the code to try doing a toString() to non-string values (to convert numbers). That way it's string in/string out.

@alex-seville

P.S. Read v.1.0.3 won't accept objects or arrays as a default value (https://github.com/isaacs/read/blob/master/lib/read.js#L11)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment