Debian Codegraph @

path2/windows/join.js

raw
1 'use strict';
2
3 var normalize = require('./normalize');
4
5 module.exports = function () {
6 var paths, joined, f;
7
8 f = function (p) {
9 if (typeof p !== 'string') {
10 throw new TypeError('Arguments to path.join must be strings');
11 }
12 return p;
13 };
14
15 paths = Array.prototype.filter.call(arguments, f);
16 joined = paths.join('\\');
17
18 // Make sure that the joined path doesn't start with two slashes, because
19 // normalize() will mistake it for an UNC path then.
20 //
21 // This step is skipped when it is very clear that the user actually
22 // intended to point at an UNC path. This is assumed when the first
23 // non-empty string arguments starts with exactly two slashes followed by
24 // at least one more non-slash character.
25 //
26 // Note that for normalize() to treat a path as an UNC path it needs to
27 // have at least 2 components, so we don't filter for that here.
28 // This means that the user can use join to construct UNC paths from
29 // a server name and a share name; for example:
30 // path.join('//server', 'share') -> '\\\\server\\share\')
31 if (!/^[\\\/]{2}[^\\\/]/.test(paths[0])) {
32 joined = joined.replace(/^[\\\/]{2,}/, '\\');
33 }
34
35 return normalize(joined);
36 };