| 347 | } |
| 348 | |
| 349 | function fromFileUrl(url: URL): Effect.Effect<string, BadArgument> { |
| 350 | if (url.protocol !== "file:") { |
| 351 | return Effect.fail( |
| 352 | new BadArgument({ |
| 353 | module: "Path", |
| 354 | method: "fromFileUrl", |
| 355 | description: "URL must be of scheme file" |
| 356 | }) |
| 357 | ) |
| 358 | } else if (url.hostname !== "") { |
| 359 | return Effect.fail( |
| 360 | new BadArgument({ |
| 361 | module: "Path", |
| 362 | method: "fromFileUrl", |
| 363 | description: "Invalid file URL host" |
| 364 | }) |
| 365 | ) |
| 366 | } |
| 367 | const pathname = url.pathname |
| 368 | for (let n = 0; n < pathname.length; n++) { |
| 369 | if (pathname[n] === "%") { |
| 370 | const third = pathname.codePointAt(n + 2)! | 0x20 |
| 371 | if (pathname[n + 1] === "2" && third === 102) { |
| 372 | return Effect.fail( |
| 373 | new BadArgument({ |
| 374 | module: "Path", |
| 375 | method: "fromFileUrl", |
| 376 | description: "must not include encoded / characters" |
| 377 | }) |
| 378 | ) |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | return Effect.succeed(decodeURIComponent(pathname)) |
| 383 | } |
| 384 | |
| 385 | const resolve: Path["resolve"] = function resolve() { |
| 386 | let resolvedPath = "" |