MCPcopy Create free account
hub / github.com/VirtualHotBar/NetMount / formatPath

Function formatPath

src/utils/utils.ts:239–269  ·  view source on GitHub ↗
(path: string, isWindows: boolean = false)

Source from the content-addressed store, hash-verified

237 * @returns 格式化后的路径
238 */
239export function formatPath(path: string, isWindows: boolean = false): string {
240 if (!path || typeof path !== 'string') {
241 return ''
242 }
243
244 // 统一替换反斜杠为正斜杠,并合并多个连续的斜杠
245 let formattedPath = path.replace(/\\/g, '/').replace(/\/+/g, '/')
246
247 if (isWindows) {
248 // Windows 路径处理
249 if (/^[A-Za-z]/.test(formattedPath)) {
250 // 以字母开头,需要添加驱动器冒号
251 if (formattedPath.substring(1, 2) !== ':') {
252 formattedPath =
253 formattedPath.substring(0, 1).toUpperCase() + ':' + formattedPath.substring(1)
254 }
255 } else if (formattedPath.startsWith('/')) {
256 // 以斜杠开头,移除开头的斜杠
257 formattedPath = formattedPath.substring(1)
258 // 递归处理,确保正确处理所有情况
259 return formatPath(formattedPath, isWindows)
260 }
261 } else {
262 // Unix/Linux 路径处理:确保以斜杠开头
263 if (!formattedPath.startsWith('/')) {
264 formattedPath = '/' + formattedPath
265 }
266 }
267
268 return formattedPath
269}
270
271export function mergeObjects<T>(target: T, source: Partial<T>): T {
272 for (const key in source) {

Callers 14

AddMount_pageFunction · 0.90
reducerFunction · 0.90
Setting_pageFunction · 0.90
netmountDataDirFunction · 0.90
defaultCacheDirFunction · 0.90
rcloneConfigFileFunction · 0.90
netmountLogDirFunction · 0.90
rcloneLogFileFunction · 0.90
openlistLogFileFunction · 0.90
openlistDataDirFunction · 0.90
sidecarLogFileFunction · 0.90
startRcloneFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected