-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
479e45c
commit a9857b8
Showing
5 changed files
with
40 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |