blob: 0c2656b5653a002748602bc4b895c5d7b972bd33 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
const { URL } = require('url')
const replace = '***'
const tokenRegex = /\bnpm_[a-zA-Z0-9]{36}\b/g
const guidRegex = /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/g
const cleanUrl = (str) => {
if (typeof str !== 'string' || !str) {
return str
}
try {
const url = new URL(str)
if (url.password) {
url.password = replace
str = url.toString()
}
} catch {
// ignore errors
}
return str
.replace(tokenRegex, `npm_${replace}`)
.replace(guidRegex, `npm_${replace}`)
}
module.exports = cleanUrl
|