MCPcopy
hub / github.com/electerm/electerm / resolve

Function resolve

src/client/common/resolve.js:15–48  ·  view source on GitHub ↗
(basePath, nameOrDot)

Source from the content-addressed store, hash-verified

13}
14
15export default function resolve (basePath, nameOrDot) {
16 const hasWinDrive = (path) => /^[a-zA-Z]:/.test(path)
17 const isWin = basePath.includes('\\') || nameOrDot.includes('\\') || hasWinDrive(basePath) || hasWinDrive(nameOrDot)
18 const sep = isWin ? '\\' : '/'
19 if (/^[a-zA-Z]:/.test(nameOrDot)) {
20 return nameOrDot.replace(/^\//, '').replace(/\//g, sep)
21 }
22 if (nameOrDot.startsWith('/')) {
23 return nameOrDot.replace(/\\/g, sep)
24 }
25 if (nameOrDot.startsWith('\\\\')) {
26 return nameOrDot
27 }
28 if (nameOrDot === '..') {
29 if (isWslDistroRoot(basePath)) {
30 return '/'
31 }
32 const baseEndsWithSep = basePath.endsWith(sep)
33 const parts = basePath.split(sep)
34 if (parts.length > 1) {
35 parts.pop()
36 if (isWin && parts.length === 1) {
37 return baseEndsWithSep ? '/' : parts.join(sep)
38 }
39 return parts.join(sep) || '/'
40 }
41 return '/'
42 }
43 if (isWslDistroRoot(basePath) && !basePath.endsWith(sep)) {
44 return basePath + sep + nameOrDot
45 }
46 const result = basePath.endsWith(sep) ? basePath + nameOrDot : basePath + sep + nameOrDot
47 return isWin && result.length === 3 && result.endsWith(':\\') ? '/' : result
48}
49
50export const osResolve = (...args) => {
51 return window.pre.resolve(...args)

Callers 15

install.jsFile · 0.85
installFromDmgFunction · 0.85
httpDownloadFunction · 0.85
httpGetFunction · 0.85
resolve.spec.jsFile · 0.85
ftp.spec.jsFile · 0.85
getVersionFunction · 0.85
createTestDbFunction · 0.85
closeFunction · 0.85
closeFunction · 0.85
closeFunction · 0.85

Calls 2

hasWinDriveFunction · 0.85
isWslDistroRootFunction · 0.85

Tested by 9

getVersionFunction · 0.68
createTestDbFunction · 0.68
closeFunction · 0.68
closeFunction · 0.68
closeFunction · 0.68
startFtpServerFunction · 0.68
waitForIdleFunction · 0.68
closeFunction · 0.68
onDataFunction · 0.68