MCPcopy Index your code
hub / github.com/nodejs/node / join

Function join

lib/path.js:506–599  ·  view source on GitHub ↗

* @param {...string} args * @returns {string}

(...args)

Source from the content-addressed store, hash-verified

504 * @returns {string}
505 */
506 join(...args) {
507 if (args.length === 0)
508 return '.';
509
510 const path = [];
511 for (let i = 0; i < args.length; ++i) {
512 const arg = args[i];
513 validateString(arg, 'path');
514 if (arg.length > 0) {
515 ArrayPrototypePush(path, arg);
516 }
517 }
518
519 if (path.length === 0)
520 return '.';
521
522 const firstPart = path[0];
523 let joined = ArrayPrototypeJoin(path, '\\');
524
525 // Make sure that the joined path doesn't start with two slashes, because
526 // normalize() will mistake it for a UNC path then.
527 //
528 // This step is skipped when it is very clear that the user actually
529 // intended to point at a UNC path. This is assumed when the first
530 // non-empty string arguments starts with exactly two slashes followed by
531 // at least one more non-slash character.
532 //
533 // Note that for normalize() to treat a path as a UNC path it needs to
534 // have at least 2 components, so we don't filter for that here.
535 // This means that the user can use join to construct UNC paths from
536 // a server name and a share name; for example:
537 // path.join('//server', 'share') -> '\\\\server\\share\\')
538 let needsReplace = true;
539 let slashCount = 0;
540 if (isPathSeparator(StringPrototypeCharCodeAt(firstPart, 0))) {
541 ++slashCount;
542 const firstLen = firstPart.length;
543 if (firstLen > 1 &&
544 isPathSeparator(StringPrototypeCharCodeAt(firstPart, 1))) {
545 ++slashCount;
546 if (firstLen > 2) {
547 if (isPathSeparator(StringPrototypeCharCodeAt(firstPart, 2)))
548 ++slashCount;
549 else {
550 // We matched a UNC path in the first part
551 needsReplace = false;
552 }
553 }
554 }
555 }
556 if (needsReplace) {
557 // Find any more consecutive slashes we need to replace
558 while (slashCount < joined.length &&
559 isPathSeparator(StringPrototypeCharCodeAt(joined, slashCount))) {
560 slashCount++;
561 }
562
563 // Replace the slashes if needed

Callers 15

GetAnnotationInfoMethod · 0.90
HasRunMethod · 0.90
HasRunMethod · 0.90
GetTestStatusMethod · 0.90
IsSuiteFunction · 0.90
GetSuitesFunction · 0.90
MainFunction · 0.90
testcfg.pyFile · 0.90
ListTestsMethod · 0.90
ListTestsMethod · 0.90
MainFunction · 0.90
v8_presubmit.pyFile · 0.90

Calls 4

isPathSeparatorFunction · 0.85
isWindowsReservedNameFunction · 0.85
someMethod · 0.80
pushMethod · 0.45

Tested by 9

GetAnnotationInfoMethod · 0.72
HasRunMethod · 0.72
HasRunMethod · 0.72
GetTestStatusMethod · 0.72
IsSuiteFunction · 0.72
GetSuitesFunction · 0.72
MainFunction · 0.72
ListTestsMethod · 0.72
ListTestsMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…