tr-promised-readline
v0.0.2
Published
Promise based wrapper around readline.
Downloads
3
Readme
tr-promised-readline
A Javascript wrapper on top of readline.
Examples
const TrPromisedReadline = require('tr-promised-readline');
var r = new TrPromisedReadline();
(r.question('What is your name? ')
.then(function(res) {
console.log('Hello ' + res + '. Nice to meet you.');
})
.catch(function(e) {
console.log('Too bad :(');
throw e;
}));
And somewhat more elaborate use case.
const TrPromisedReadline = require('tr-promised-readline');
var r = new TrPromisedReadline();
(Promise.all([r.question('Name: ', { failOnEmpty: true }),
r.question('Your motto: '),
r.question('Email address: ',
{ allowedReplies: /^[a-z0-9_-]+@[a-z0-9_-]+(.[a-z0-9_-]+)*$/ }),
r.question('Country code: ',
{ allowedReplies: ['FI','EE','NL','GB','ES'], caseSensitive: false }),
r.question('Default currency: ',
{ allowedReplies: ['EUR','USD','GBP'], caseSensitive: false })])
.then(function(res) {
var name = res[0], motto = res[1], email = res[2], country = res[3], currency = res[4];
// And so on ...
})
.catch(function(e) {
throw e;
})
License
MIT