Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function validate (addr) {
try {
var err = userValidate.email(addr)
if (err != null) return err
} catch (_err) {
return new Error('Error validating address.')
}
return null
}
function readEmail (email, opts) {
if (email) {
const error = userValidate.email(email)
if (error) {
opts.log && opts.log.warn(error.message)
} else {
return email.trim()
}
}
return read({prompt: 'Email (this IS public): ', default: email || ''})
.then(username => readEmail(username, opts))
}
function readEmail (msg, email, opts, isRetry) {
if (!msg) msg = 'email (this IS public): '
if (isRetry && email) {
const error = userValidate.email(email)
if (error) {
opts.log && opts.log.warn(error.message)
} else {
return email.trim()
}
}
return read({prompt: msg, default: email || ''})
.then((username) => readEmail(msg, username, opts, true))
}