MCPcopy Create free account
hub / github.com/Effect-TS/effect / fromFileUrl

Function fromFileUrl

packages/effect/src/Path.ts:349–383  ·  view source on GitHub ↗
(url: URL)

Source from the content-addressed store, hash-verified

347}
348
349function 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
385const resolve: Path["resolve"] = function resolve() {
386 let resolvedPath = ""

Callers

nothing calls this directly

Calls 2

failMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected