CLI email prompt featuring autocompletion and validation.
Powers 𝚫now --login
.
const prompt = require('email-prompt');
prompt({ /* opts */ })
.then((email) => {
console.log('\n> Hello ' + val);
))
.catch(() => {
console.log('\n> Aborted!');
})
To run the demo, clone the project and run:
$ npm install
$ node demo
start
(String
): the beginning of the prompt. Defaults to> Enter your email:
domains
(Set
): domain names to autocomplete (asString
). Defaults to:aol.com
gmail.com
google.com
yahoo.com
ymail.com
hotmail.com
live.com
outlook.com
inbox.com
mail.com
gmx.com
forceLowerCase
(Boolean
): converts all input to lowercase. Defaults totrue
.suggestionColor
(String
): a chalk color. Defaults togray
autocompleteChars
(Set
): a set of chars that trigger autocompletion. Defaults to:- ↹ Tab
- ↵ Return (enter)
- → Right arrow
resolveChars
(Set
): a set of chars that resolve the promise. Defaults to ↵returnabortChars
(Set
): a set of chars that abort the process. Defaults to Ctrl+CallowInvalidChars
(Boolean
): controls whether non-email chars are accepted. Defaults tofalse
Some important implementation details:
email-prompt
automatically adapts the mode ofprocess.stdin
for you.- The
stdin
stream isresume
d andpause
d upon the promise being settled. - When the promise resolves or rejects, the previous stdin mode is restored.
- The
tty
mode is set toraw
, which means all the caret interactions that you come to expect in a regularstdin
prompt are simulated. This gives us fine-grained control over the output and powers the validation.