mirror of
https://github.com/djdevin/recflare.git
synced 2026-10-28 00:18:58 -07:00
Initial commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
/** Redacts keys from a url */
|
||||
export function redactUrl(_url: URL | string): URL {
|
||||
let url: URL
|
||||
if (typeof _url === 'string') {
|
||||
url = new URL(_url)
|
||||
} else {
|
||||
url = new URL(_url.toString()) // clone
|
||||
}
|
||||
for (const [key] of url.searchParams) {
|
||||
if (/key|token|secret|password|passwd|auth|credential/i.test(key)) {
|
||||
url.searchParams.set(key, 'REDACTED')
|
||||
}
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a URLSearchParams object into an array of "key=value" strings.
|
||||
*
|
||||
* @param searchParams - The URLSearchParams object to convert.
|
||||
* @returns An array of strings, where each string is in the format "key=value".
|
||||
*/
|
||||
export function searchParamsToArray(searchParams: URLSearchParams): string[] {
|
||||
const result: string[] = []
|
||||
for (const [key, value] of searchParams.entries()) {
|
||||
result.push(`${key}=${value}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user