I would use just question
and move your custom login into limit
callback. For instance, one idea could be checking if the input is an integer and it is in the range between 0-9
:
var readlineSync = require('readline-sync');
var number_of_people = readlineSync.question('How many people are you going with?', {
limit: function(i) {
const input = Number(i);
return Number.isInteger(input) && input > 0 && input < 10;
}});
You could also make use of regexp; just have your callback return true
when the input is valid based on your logic
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…