MCPcopy Create free account
hub / github.com/isomorphic-git/isomorphic-git / normalize

Function normalize

src/utils/join.js:88–124  ·  view source on GitHub ↗
(path)

Source from the content-addressed store, hash-verified

86}
87
88function normalize(path) {
89 if (!path.length) return '.'
90
91 // Normalise backslashes to forward slashes before any other processing.
92 path = path.replace(/\\/g, '/')
93
94 const drivePrefix = getWindowsDrivePrefix(path)
95 // isAbsolute: Unix root ('/foo') OR Windows drive+slash ('C:/foo').
96 const isAbsolute =
97 path[0] === '/' || (drivePrefix !== null && path[2] === '/')
98 const trailingSeparator = path.at(-1) === '/'
99
100 // Strip the drive prefix before feeding into normalizeString so that the
101 // core algorithm only ever sees a plain POSIX-style string.
102 const pathBody = drivePrefix ? path.slice(2) : path
103
104 let normalized = normalizeString(pathBody, !isAbsolute)
105
106 if (!normalized.length) {
107 const root = drivePrefix
108 ? isAbsolute
109 ? drivePrefix + '/'
110 : drivePrefix
111 : isAbsolute
112 ? '/'
113 : '.'
114 return trailingSeparator && !isAbsolute ? root + '/' : root
115 }
116 if (trailingSeparator) normalized += '/'
117
118 if (drivePrefix) {
119 return isAbsolute
120 ? `${drivePrefix}/${normalized}`
121 : `${drivePrefix}${normalized}`
122 }
123 return isAbsolute ? `/${normalized}` : normalized
124}
125
126export function join(...args) {
127 if (args.length === 0) return '.'

Callers 1

joinFunction · 0.85

Calls 3

getWindowsDrivePrefixFunction · 0.85
normalizeStringFunction · 0.85
sliceMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…