A nodejs library for issuing and handling responses to yes/no questions
Supports Node 8+.
Installation
npm install yesno
Usage
; // modern es modules approach // *OR* const yesno = ; // commonjs approach
Examples
basic
const ok = await ;
yesno accepts yes
, y
, no
, and n
values by default.
All yesno responses are case insensitive.
Custom Yes/No values
const ok = await ; console;
Now the question only responds to groovy
as yes and or what
as no.
No default value
Sometimes you may want to ensure the user didn't accidentally accept a default. You can disable the default response by passing null as the defaultValue parameter.
const ok = await ;
Handling invalid responses
By default, if the user enters a value that isn't recognized as an acceptable response, it will print out a message like:
Invalid response.
Answer either yes : (yes, y)
Or no : (no, n)
and re-ask the question. If you want to change this behavior, you can set the invalid handler before asking your question:
const ok = await ;