diff options
Diffstat (limited to 'deps/npm/lib/utils/replace-info.js')
-rw-r--r-- | deps/npm/lib/utils/replace-info.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/deps/npm/lib/utils/replace-info.js b/deps/npm/lib/utils/replace-info.js new file mode 100644 index 0000000000..a613a3755f --- /dev/null +++ b/deps/npm/lib/utils/replace-info.js @@ -0,0 +1,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 |