blob: a613a3755fab047043d3450987d9df98ecefe3ff (
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 strings
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
|