• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1const URL = require('url').URL
2
3// replaces auth info in an array
4//  of arguments or in a strings
5function replaceInfo (arg) {
6  const isArray = Array.isArray(arg)
7  const isString = typeof arg === 'string'
8
9  if (!isArray && !isString) return arg
10
11  const args = isString ? arg.split(' ') : arg
12  const info = args.map(arg => {
13    try {
14      const url = new URL(arg)
15      return url.password === '' ? arg : arg.replace(url.password, '***')
16    } catch (e) { return arg }
17  })
18
19  return isString ? info.join(' ') : info
20}
21
22module.exports = replaceInfo
23