PHP 8.2.30
Preview: read-user-info.js Size: 2.08 KB
/proc/thread-self/root/proc/thread-self/root/lib/node_modules/npm/lib/utils/read-user-info.js

'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))
}

Directory Contents

Dirs: 1 × Files: 48

Name Size Perms Modified Actions
- drwxr-xr-x 2024-03-03 22:36:29
Edit Download
211 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
1.70 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
290 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
1.74 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
1.24 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
363 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
451 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
446 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
6.04 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
13.44 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
657 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
761 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
4.48 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
484 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
1.70 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
556 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
294 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
166 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
153 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
59 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
496 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
364 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
234 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
1.81 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
1.08 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
2.17 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
973 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
290 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
541 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
819 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
721 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
210 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
399 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
653 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
548 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
895 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
783 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
329 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
2.08 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
556 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
349 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
1.38 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
173 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
343 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
85 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
1.29 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
576 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
556 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).