type stringOrRecord = string | Record<string, string>

export function url (path: string, ...args: stringOrRecord[]): string {
  const parts = [path]
  let i = 0
  while (i < args.length && typeof args[i] === 'string') {
    parts.push(args[i] as string)
    i++
  }

  const result = parts.join('/').replace(/(?<!:)\/\/+/g, '/')
  const qs = []
  while (i < args.length && Object.keys(args[i] as Record<string, string>).length > 0) {
    const usp = new URLSearchParams(args[i] as Record<string, string>)
    qs.push(usp.toString())
    i++
  }

  return qs.length === 0 ? result : `${result}?${qs.join('&')}`
}

console.log(url("https://[Log in to view URL]", "foo", {"bar": "baz"}))

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: