MCPcopy Index your code
hub / github.com/npmx-dev/npmx.dev / normalizePath

Function normalizePath

server/utils/import-resolver.ts:30–46  ·  view source on GitHub ↗

* Normalize a path by resolving . and .. segments

(path: string)

Source from the content-addressed store, hash-verified

28 * Normalize a path by resolving . and .. segments
29 */
30function normalizePath(path: string): string {
31 const parts = path.split('/')
32 const result: string[] = []
33
34 for (const part of parts) {
35 if (part === '.' || part === '') {
36 continue
37 }
38 if (part === '..') {
39 result.pop()
40 } else {
41 result.push(part)
42 }
43 }
44
45 return result.join('/')
46}
47
48/**
49 * Get the directory of a file path.

Callers 1

resolveRelativeImportFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected