11cb0ef41Sopenharmony_ciconst { URL } = require('url') 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst replace = '***' 41cb0ef41Sopenharmony_ciconst tokenRegex = /\bnpm_[a-zA-Z0-9]{36}\b/g 51cb0ef41Sopenharmony_ciconst guidRegex = /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/g 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst cleanUrl = (str) => { 81cb0ef41Sopenharmony_ci if (typeof str !== 'string' || !str) { 91cb0ef41Sopenharmony_ci return str 101cb0ef41Sopenharmony_ci } 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci try { 131cb0ef41Sopenharmony_ci const url = new URL(str) 141cb0ef41Sopenharmony_ci if (url.password) { 151cb0ef41Sopenharmony_ci url.password = replace 161cb0ef41Sopenharmony_ci str = url.toString() 171cb0ef41Sopenharmony_ci } 181cb0ef41Sopenharmony_ci } catch { 191cb0ef41Sopenharmony_ci // ignore errors 201cb0ef41Sopenharmony_ci } 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci return str 231cb0ef41Sopenharmony_ci .replace(tokenRegex, `npm_${replace}`) 241cb0ef41Sopenharmony_ci .replace(guidRegex, `npm_${replace}`) 251cb0ef41Sopenharmony_ci} 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_cimodule.exports = cleanUrl 28