* Parses a string value into a URI object. * @param value the string value of the URI * @param defaultScheme the default scheme to use if none is provided in the value. * - if a `string`, it will be used as the default scheme * - if a `URI`, its scheme will be used as the default scheme
(value: string, defaultScheme: URI | string | null)
| 56 | * @throws if no scheme is provided in value and no default scheme is given |
| 57 | */ |
| 58 | static parse(value: string, defaultScheme: URI | string | null): URI { |
| 59 | const match = _regexp.exec(value); |
| 60 | if (!match) { |
| 61 | return new URI(); |
| 62 | } |
| 63 | defaultScheme = |
| 64 | defaultScheme instanceof URI |
| 65 | ? defaultScheme.scheme |
| 66 | : (defaultScheme as string | null); |
| 67 | const scheme = match[2] || defaultScheme; |
| 68 | if (isNone(scheme)) { |
| 69 | throw new Error(`Invalid URI: The URI scheme is missing: ${value}`); |
| 70 | } |
| 71 | return new URI({ |
| 72 | scheme, |
| 73 | authority: percentDecode(match[4] ?? _empty), |
| 74 | path: pathUtils.fromFsPath(percentDecode(match[5] ?? _empty))[0], |
| 75 | query: percentDecode(match[7] ?? _empty), |
| 76 | fragment: percentDecode(match[9] ?? _empty), |
| 77 | }); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @deprecated Will not work with web extension. Use only for testing. |