'use strict' const Bluebird = require('bluebird') const readAsync = Bluebird.promisify(require('read')) const userValidate = require('npm-user-validate') const log = require('npmlog') exports.otp = readOTP exports.password = readPassword exports.username = readUsername exports.email = readEmail function read (opts) { return Bluebird.try(() => { log.clearProgress() return readAsync(opts) }).finally(() => { log.showProgress() }) } function readOTP (msg, otp, isRetry) { if (!msg) { msg = [ 'This command requires a one-time password (OTP) from your authenticator app.', 'Enter one below. You can also pass one on the command line by appending --otp=123456.', 'For more information, see:', 'https://docs.npmjs.com/getting-started/using-two-factor-authentication', 'Enter OTP: ' ].join('\n') } if (isRetry && otp && /^[\d ]+$|^[A-Fa-f0-9]{64,64}$/.test(otp)) return otp.replace(/\s+/g, '') return read({prompt: msg, default: otp || ''}) .then((otp) => readOTP(msg, otp, true)) } function readPassword (msg, password, isRetry) { if (!msg) msg = 'npm password: ' if (isRetry && password) return password return read({prompt: msg, silent: true, default: password || ''}) .then((password) => readPassword(msg, password, true)) } function readUsername (msg, username, opts, isRetry) { if (!msg) msg = 'npm username: ' if (isRetry && username) { const error = userValidate.username(username) if (error) { opts.log && opts.log.warn(error.message) } else { return Promise.resolve(username.trim()) } } return read({prompt: msg, default: username || ''}) .then((username) => readUsername(msg, username, opts, true)) } 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)) }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
completion | Folder | 0755 |
|
|
ansi-trim.js | File | 211 B | 0644 |
|
cache-file.js | File | 1.7 KB | 0644 |
|
child-path.js | File | 290 B | 0644 |
|
completion.sh | File | 1.74 KB | 0755 |
|
correct-mkdir.js | File | 1.24 KB | 0644 |
|
deep-sort-object.js | File | 363 B | 0644 |
|
depr-check.js | File | 451 B | 0644 |
|
did-you-mean.js | File | 446 B | 0644 |
|
error-handler.js | File | 6.04 KB | 0644 |
|
error-message.js | File | 13.44 KB | 0644 |
|
escape-arg.js | File | 657 B | 0644 |
|
escape-exec-path.js | File | 761 B | 0644 |
|
funding.js | File | 4.48 KB | 0644 |
|
gently-rm.js | File | 484 B | 0644 |
|
git.js | File | 1.7 KB | 0644 |
|
gunzip-maybe.js | File | 556 B | 0644 |
|
is-registry.js | File | 294 B | 0644 |
|
is-windows-bash.js | File | 166 B | 0644 |
|
is-windows-shell.js | File | 153 B | 0644 |
|
is-windows.js | File | 59 B | 0644 |
|
lifecycle-cmd.js | File | 496 B | 0644 |
|
lifecycle.js | File | 364 B | 0644 |
|
link.js | File | 234 B | 0644 |
|
locker.js | File | 1.81 KB | 0644 |
|
metrics-launch.js | File | 1.08 KB | 0644 |
|
metrics.js | File | 2.17 KB | 0644 |
|
module-name.js | File | 973 B | 0644 |
|
move.js | File | 290 B | 0644 |
|
no-progress-while-running.js | File | 541 B | 0644 |
|
open-url.js | File | 819 B | 0644 |
|
otplease.js | File | 721 B | 0644 |
|
output.js | File | 210 B | 0644 |
|
package-id.js | File | 399 B | 0644 |
|
parse-json.js | File | 653 B | 0644 |
|
perf.js | File | 548 B | 0644 |
|
pick-manifest-from-registry-metadata.js | File | 895 B | 0644 |
|
pulse-till-done.js | File | 783 B | 0644 |
|
read-local-package.js | File | 329 B | 0644 |
|
read-user-info.js | File | 2.08 KB | 0644 |
|
replace-info.js | File | 556 B | 0644 |
|
save-stack.js | File | 349 B | 0644 |
|
spawn.js | File | 1.38 KB | 0644 |
|
temp-filename.js | File | 173 B | 0644 |
|
umask.js | File | 343 B | 0644 |
|
unix-format-path.js | File | 85 B | 0644 |
|
unsupported.js | File | 1.29 KB | 0644 |
|
usage.js | File | 576 B | 0644 |
|
warn-deprecated.js | File | 556 B | 0644 |
|