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

Function clean

packages/effect/src/IgnoreFile.ts:496–518  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

494
495// Go's `path.Clean`
496const clean = (path: string): string => {
497 if (path === "") {
498 return "."
499 }
500 const rooted = path.startsWith("/")
501 const out: Array<string> = []
502 for (const segment of path.split("/")) {
503 if (segment === "" || segment === ".") {
504 continue
505 }
506 if (segment === "..") {
507 if (out.length > 0 && out[out.length - 1] !== "..") {
508 out.pop()
509 } else if (!rooted) {
510 out.push("..")
511 }
512 continue
513 }
514 out.push(segment)
515 }
516 const joined = out.join("/")
517 return rooted ? `/${joined}` : joined === "" ? "." : joined
518}
519
520// Port of Go's `filepath.Match(pattern, ".")`, which `PatternMatcher` uses to
521// reject bad syntax. Only chunks reached before a mismatch are checked.

Callers 1

parseDockerignoreFunction · 0.70

Calls 3

pushMethod · 0.65
splitMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected