Welcome to mirror list, hosted at ThFree Co, Russian Federation.

replace-info.js « utils « lib - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7b6d7ad0895cc59b93d12cb9ebffdd021a215e4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const { URL } = require('url')

// replaces auth info in an array
//  of arguments or in a string
function replaceInfo (arg) {
  const isArray = Array.isArray(arg)
  const isString = typeof arg === 'string'

  if (!isArray && !isString) return arg

  const args = isString ? arg.split(' ') : arg
  const info = args.map(arg => {
    try {
      const url = new URL(arg)
      return url.password === '' ? arg : arg.replace(url.password, '***')
    } catch (e) { return arg }
  })

  return isString ? info.join(' ') : info
}

module.exports = replaceInfo