Line data Source code
1 : /**
2 : * The one place a string becomes a `URL` in this package. Every entry point
3 : * here takes input that arrived over a URL bar, so a parse failure is a value
4 : * to branch on rather than an exception each caller has to remember to catch.
5 : */
6 0 : export function parseUrl(value: string | URL, base?: string): URL | undefined {
7 0 : try {
8 0 : return new URL(value instanceof URL ? value.href : value, base)
9 : } catch {
10 0 : return undefined
11 : }
12 : }
13 :
14 : /**
15 : * Lets the parsers accept the path-and-query form a router hands them
16 : * (`/v1/checkout?...`) as readily as a full href. It is never read back: only
17 : * the pathname and the query survive parsing, and `.invalid` is reserved by
18 : * RFC 2606 so a bug that leaked it could not reach a real host.
19 : */
20 : export const CONTRACT_PARSE_BASE = 'https://billing.invalid/'
|