* @param {...string} args * @returns {string}
(...args)
| 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 |
searching dependent graphs…