Email-prompt

email-prompt

CLI email prompt featuring autocompletion and validation.

email-prompt Powers 𝚫now --login and provides a nice promised based API for email autocompletion and validation.

It's customiziable with the below options:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{
  start :'> Enter your email: ',
  domains :new Set([
    'aol.com',
    'gmail.com',
    'google.com',
    'yahoo.com',
    'ymail.com',
    'hotmail.com',
    'live.com',
    'outlook.com',
    'inbox.com',
    'mail.com',
    'gmx.com',
    'icloud.com'
  ]),
  forceLowerCase :true,
  suggestionColor :'gray',
  autoCompleteChars :new Set([
    '\t' /* tab */,
    '\r' /* return */,
    '\x1b[C' /* right arrow */,
    ' ' /* spacebar */
  ]),
  resolveChars :new Set(['\r']),
  abortChars :new Set(['\x03']),
  allowInvalidChars :false
}

Get it: npm install --save email-prompt

Sample usage:

1
2
3
4
5
6
7
8
const prompt = require('email-prompt');
prompt({ /* opts */ })
.then((email) => {
  console.log('\n> Hello ' + val);
))
.catch(() => {
  console.log('\n> Aborted!');
})

Important to note:

  • email-prompt automatically adapts the mode of process.stdin for you.
  • The stdin stream is resumed and paused upon the promise being settled.
  • When the promise resolves or rejects, the previous stdin mode is restored.
  • The tty mode is set to raw, which means all the caret interactions that you come to expect in a regular stdin prompt are simulated. This gives us fine-grained control over the output and powers the validation.

GIF FTW!

email-prompt

Suggest a module

Comments