MCPcopy Create free account
hub / github.com/denoland/std / normalize

Function normalize

path/posix/normalize.ts:44–63  ·  view source on GitHub ↗
(path: string | URL)

Source from the content-addressed store, hash-verified

42 * @returns The normalized path.
43 */
44export function normalize(path: string | URL): string {
45 if (path instanceof URL) {
46 path = fromFileUrl(path);
47 }
48 assertArg(path);
49
50 const isAbsolute = isPosixPathSeparator(path.charCodeAt(0));
51 const trailingSeparator = isPosixPathSeparator(
52 path.charCodeAt(path.length - 1),
53 );
54
55 // Normalize the path
56 path = normalizeString(path, !isAbsolute, "/", isPosixPathSeparator);
57
58 if (path.length === 0 && !isAbsolute) path = ".";
59 if (path.length > 0 && trailingSeparator) path += "/";
60
61 if (isAbsolute) return `/${path}`;
62 return path;
63}

Callers 2

normalizeGlobFunction · 0.90
joinFunction · 0.90

Calls 4

fromFileUrlFunction · 0.90
assertArgFunction · 0.90
isPosixPathSeparatorFunction · 0.90
normalizeStringFunction · 0.90

Tested by

no test coverage detected