MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / normalize

Function normalize

src/platform/vscode-path/path.ts:345–431  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

343 },
344
345 normalize(path: string): string {
346 validateString(path, 'path');
347 const len = path.length;
348 if (len === 0) {
349 return '.';
350 }
351 let rootEnd = 0;
352 let device;
353 let isAbsolute = false;
354 const code = path.charCodeAt(0);
355
356 // Try to match a root
357 if (len === 1) {
358 // `path` contains just a single char, exit early to avoid
359 // unnecessary work
360 return isPosixPathSeparator(code) ? '\\' : path;
361 }
362 if (isPathSeparator(code)) {
363 // Possible UNC root
364
365 // If we started with a separator, we know we at least have an absolute
366 // path of some kind (UNC or otherwise)
367 isAbsolute = true;
368
369 if (isPathSeparator(path.charCodeAt(1))) {
370 // Matched double path separator at beginning
371 let j = 2;
372 let last = j;
373 // Match 1 or more non-path separators
374 while (j < len && !isPathSeparator(path.charCodeAt(j))) {
375 j++;
376 }
377 if (j < len && j !== last) {
378 const firstPart = path.slice(last, j);
379 // Matched!
380 last = j;
381 // Match 1 or more path separators
382 while (j < len && isPathSeparator(path.charCodeAt(j))) {
383 j++;
384 }
385 if (j < len && j !== last) {
386 // Matched!
387 last = j;
388 // Match 1 or more non-path separators
389 while (j < len && !isPathSeparator(path.charCodeAt(j))) {
390 j++;
391 }
392 if (j === len) {
393 // We matched a UNC root only
394 // Return the normalized version of the UNC root since there
395 // is nothing left to process
396 return `\\\\${firstPart}\\${path.slice(last)}\\`;
397 }
398 if (j !== last) {
399 // We matched a UNC root with leftovers
400 device = `\\\\${firstPart}\\${path.slice(last, j)}`;
401 rootEnd = j;
402 }

Callers

nothing calls this directly

Calls 5

validateStringFunction · 0.85
isPosixPathSeparatorFunction · 0.85
isWindowsDeviceRootFunction · 0.85
normalizeStringFunction · 0.85
isPathSeparatorFunction · 0.70

Tested by

no test coverage detected