468
469
join(...paths: string[]): string {
470
>
if (paths.length === 0) {
path.ts
471
return '.';
472
}
474
>
let joined;
475
>
let firstPart: string | undefined;
476
>
for (let i = 0; i < paths.length; ++i) {
477
>
const arg = paths[i];
478
>
validateString(arg, 'path');
479
>
if (arg.length > 0) {
480
>
if (joined === undefined) {
481
>
joined = firstPart = arg;
482
>
}
483
>
else {
484
>
joined += `\\${arg}`;
485
>
}
486
>
}
487
>
}
488
>
489
>
if (joined === undefined) {
490
return '.';
491
}
493
>
// Make sure that the joined path doesn't start with two slashes, because
494
>
// normalize() will mistake it for a UNC path then.
495
>
//
496
>
// This step is skipped when it is very clear that the user actually
497
>
// intended to point at a UNC path. This is assumed when the first
498
>
// non-empty string arguments starts with exactly two slashes followed by
499
>
// at least one more non-slash character.
500
>
//
501
>
// Note that for normalize() to treat a path as a UNC path it needs to
502
>
// have at least 2 components, so we don't filter for that here.
503
>
// This means that the user can use join to construct UNC paths from
504
>
// a server name and a share name; for example:
505
>
// path.join('//server', 'share') -> '\\\\server\\share\\')
506
>
let needsReplace = true;
507
>
let slashCount = 0;
508
>
if (typeof firstPart === 'string' && isPathSeparator(firstPart.charCodeAt(0))) {
509
++slashCount;
510
const firstLen = firstPart.length;