MCPcopy Index your code
hub / github.com/anomalyco/opencode / normalize

Function normalize

packages/app/src/context/file/path.ts:105–131  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

103
104export function createPathHelpers(scope: () => string) {
105 const normalize = (input: string) => {
106 const root = scope()
107
108 let path = unquoteGitPath(decodeFilePath(stripQueryAndHash(stripFileProtocol(input))))
109
110 // Separator-agnostic prefix stripping for Cygwin/native Windows compatibility
111 // Only case-insensitive on Windows (drive letter or UNC paths)
112 const windows = /^[A-Za-z]:/.test(root) || root.startsWith("\\\\")
113 const canonRoot = windows ? root.replace(/\\/g, "/").toLowerCase() : root.replace(/\\/g, "/")
114 const canonPath = windows ? path.replace(/\\/g, "/").toLowerCase() : path.replace(/\\/g, "/")
115 if (
116 canonPath.startsWith(canonRoot) &&
117 (canonRoot.endsWith("/") || canonPath === canonRoot || canonPath[canonRoot.length] === "/")
118 ) {
119 // Slice from original path to preserve native separators
120 path = path.slice(root.length)
121 }
122
123 if (path.startsWith("./") || path.startsWith(".\\")) {
124 path = path.slice(2)
125 }
126
127 if (path.startsWith("/") || path.startsWith("\\")) {
128 path = path.slice(1)
129 }
130 return path
131 }
132
133 const tab = (input: string) => {
134 const path = normalize(input)

Callers 3

tabFunction · 0.70
pathFromTabFunction · 0.70
normalizeDirFunction · 0.70

Calls 5

decodeFilePathFunction · 0.85
stripQueryAndHashFunction · 0.85
stripFileProtocolFunction · 0.85
unquoteGitPathFunction · 0.70
scopeFunction · 0.50

Tested by

no test coverage detected