Lines Matching refs:path
65 // Resolves . and .. elements in a path with directory names
66 function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
72 for (let i = 0; i <= path.length; ++i) {
73 if (i < path.length)
74 code = StringPrototypeCharCodeAt(path, i);
114 res += `${separator}${StringPrototypeSlice(path, lastSlash + 1, i)}`;
116 res = StringPrototypeSlice(path, lastSlash + 1, i);
154 * path.resolve([from ...], to)
164 let path;
166 path = args[i];
167 validateString(path, `paths[${i}]`);
170 if (path.length === 0) {
174 path = process.cwd();
178 // absolute path, get cwd for that drive, or the process cwd if
180 // a UNC path at this points, because UNC paths are always absolute.
181 path = process.env[`=${resolvedDevice}`] || process.cwd();
185 if (path === undefined ||
186 (StringPrototypeToLowerCase(StringPrototypeSlice(path, 0, 2)) !==
188 StringPrototypeCharCodeAt(path, 2) === CHAR_BACKWARD_SLASH)) {
189 path = `${resolvedDevice}\\`;
193 const len = path.length;
197 const code = StringPrototypeCharCodeAt(path, 0);
202 // `path` contains just a path separator
210 // absolute path of some kind (UNC or otherwise)
213 if (isPathSeparator(StringPrototypeCharCodeAt(path, 1))) {
214 // Matched double path separator at beginning
217 // Match 1 or more non-path separators
219 !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
223 const firstPart = StringPrototypeSlice(path, last, j);
226 // Match 1 or more path separators
228 isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
234 // Match 1 or more non-path separators
236 !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
242 `\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`;
251 StringPrototypeCharCodeAt(path, 1) === CHAR_COLON) {
253 device = StringPrototypeSlice(path, 0, 2);
255 if (len > 2 && isPathSeparator(StringPrototypeCharCodeAt(path, 2))) {
256 // Treat separator following drive name as an absolute path
267 // This path points to another device so it is not applicable
279 `${StringPrototypeSlice(path, rootEnd)}\\${resolvedTail}`;
287 // At this point the path should be resolved to a full absolute path,
291 // Normalize the tail path
301 * @param {string} path
304 normalize(path) {
305 validateString(path, 'path');
306 const len = path.length;
312 const code = StringPrototypeCharCodeAt(path, 0);
316 // `path` contains just a single char, exit early to avoid
318 return isPosixPathSeparator(code) ? '\\' : path;
324 // path of some kind (UNC or otherwise)
327 if (isPathSeparator(StringPrototypeCharCodeAt(path, 1))) {
328 // Matched double path separator at beginning
331 // Match 1 or more non-path separators
333 !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
337 const firstPart = StringPrototypeSlice(path, last, j);
340 // Match 1 or more path separators
342 isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
348 // Match 1 or more non-path separators
350 !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
357 return `\\\\${firstPart}\\${StringPrototypeSlice(path, last)}\\`;
362 `\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`;
371 StringPrototypeCharCodeAt(path, 1) === CHAR_COLON) {
373 device = StringPrototypeSlice(path, 0, 2);
375 if (len > 2 && isPathSeparator(StringPrototypeCharCodeAt(path, 2))) {
376 // Treat separator following drive name as an absolute path
384 normalizeString(StringPrototypeSlice(path, rootEnd),
390 isPathSeparator(StringPrototypeCharCodeAt(path, len - 1)))
399 * @param {string} path
402 isAbsolute(path) {
403 validateString(path, 'path');
404 const len = path.length;
408 const code = StringPrototypeCharCodeAt(path, 0);
413 StringPrototypeCharCodeAt(path, 1) === CHAR_COLON &&
414 isPathSeparator(StringPrototypeCharCodeAt(path, 2)));
429 validateString(arg, 'path');
441 // Make sure that the joined path doesn't start with two slashes, because
442 // normalize() will mistake it for a UNC path then.
445 // intended to point at a UNC path. This is assumed when the first
449 // Note that for normalize() to treat a path as a UNC path it needs to
453 // path.join('//server', 'share') -> '\\\\server\\share\\')
466 // We matched a UNC path in the first part
488 * It will solve the relative path from `from` to `to`, for instance
545 // Compare paths to find the longest common path from root
557 // We found a mismatch before the first common path separator was seen, so
566 // We get here if `from` is the exact base path for `to`.
579 // We get here if `to` is the exact base path for `from`.
593 // Generate the relative path based on the path difference between `to` and
604 // Lastly, append the rest of the destination (`to`) path that comes after
605 // the common path parts
615 * @param {string} path
618 toNamespacedPath(path) {
620 if (typeof path !== 'string' || path.length === 0)
621 return path;
623 const resolvedPath = win32.resolve(path);
626 return path;
633 // Matched non-long UNC root, convert the path to a long UNC path
642 // Matched device root, convert the path to a long UNC path
646 return path;
650 * @param {string} path
653 dirname(path) {
654 validateString(path, 'path');
655 const len = path.length;
660 const code = StringPrototypeCharCodeAt(path, 0);
663 // `path` contains just a path separator, exit early to avoid
665 return isPathSeparator(code) ? path : '.';
674 if (isPathSeparator(StringPrototypeCharCodeAt(path, 1))) {
675 // Matched double path separator at beginning
678 // Match 1 or more non-path separators
680 !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
686 // Match 1 or more path separators
688 isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
694 // Match 1 or more non-path separators
696 !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
701 return path;
715 StringPrototypeCharCodeAt(path, 1) === CHAR_COLON) {
717 len > 2 && isPathSeparator(StringPrototypeCharCodeAt(path, 2)) ? 3 : 2;
724 if (isPathSeparator(StringPrototypeCharCodeAt(path, i))) {
730 // We saw the first non-path separator
741 return StringPrototypeSlice(path, 0, end);
745 * @param {string} path
749 basename(path, suffix) {
752 validateString(path, 'path');
758 // path separator as an extra separator at the end of the path that can be
760 if (path.length >= 2 &&
761 isWindowsDeviceRoot(StringPrototypeCharCodeAt(path, 0)) &&
762 StringPrototypeCharCodeAt(path, 1) === CHAR_COLON) {
766 if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {
767 if (suffix === path)
771 for (let i = path.length - 1; i >= start; --i) {
772 const code = StringPrototypeCharCodeAt(path, i);
774 // If we reached a path separator that was not part of a set of path
782 // We saw the first non-path separator, remember this index in case
791 // We matched the extension, so mark this as the end of our path
796 // Extension does not match, so our result is the entire path
808 end = path.length;
809 return StringPrototypeSlice(path, start, end);
811 for (let i = path.length - 1; i >= start; --i) {
812 if (isPathSeparator(StringPrototypeCharCodeAt(path, i))) {
813 // If we reached a path separator that was not part of a set of path
820 // We saw the first non-path separator, mark this as the end of our
821 // path component
829 return StringPrototypeSlice(path, start, end);
833 * @param {string} path
836 extname(path) {
837 validateString(path, 'path');
844 // after any path separator we find
848 // path separator as an extra separator at the end of the path that can be
851 if (path.length >= 2 &&
852 StringPrototypeCharCodeAt(path, 1) === CHAR_COLON &&
853 isWindowsDeviceRoot(StringPrototypeCharCodeAt(path, 0))) {
857 for (let i = path.length - 1; i >= start; --i) {
858 const code = StringPrototypeCharCodeAt(path, i);
860 // If we reached a path separator that was not part of a set of path
869 // We saw the first non-path separator, mark this as the end of our
881 // We saw a non-dot and non-path separator before our dot, so we should
891 // The (right-most) trimmed path component is exactly '..'
897 return StringPrototypeSlice(path, startDot, end);
903 * @param {string} path
912 parse(path) {
913 validateString(path, 'path');
916 if (path.length === 0)
919 const len = path.length;
921 let code = StringPrototypeCharCodeAt(path, 0);
925 // `path` contains just a path separator, exit early to avoid
927 ret.root = ret.dir = path;
930 ret.base = ret.name = path;
938 if (isPathSeparator(StringPrototypeCharCodeAt(path, 1))) {
939 // Matched double path separator at beginning
942 // Match 1 or more non-path separators
944 !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
950 // Match 1 or more path separators
952 isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
958 // Match 1 or more non-path separators
960 !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
974 StringPrototypeCharCodeAt(path, 1) === CHAR_COLON) {
977 // `path` contains just a drive root, exit early to avoid
979 ret.root = ret.dir = path;
983 if (isPathSeparator(StringPrototypeCharCodeAt(path, 2))) {
985 // `path` contains just a drive root, exit early to avoid
987 ret.root = ret.dir = path;
994 ret.root = StringPrototypeSlice(path, 0, rootEnd);
1000 let i = path.length - 1;
1003 // after any path separator we find
1008 code = StringPrototypeCharCodeAt(path, i);
1010 // If we reached a path separator that was not part of a set of path
1019 // We saw the first non-path separator, mark this as the end of our
1031 // We saw a non-dot and non-path separator before our dot, so we should
1041 // The (right-most) trimmed path component is exactly '..'
1045 ret.base = ret.name = StringPrototypeSlice(path, startPart, end);
1047 ret.name = StringPrototypeSlice(path, startPart, startDot);
1048 ret.base = StringPrototypeSlice(path, startPart, end);
1049 ret.ext = StringPrototypeSlice(path, startDot, end);
1057 ret.dir = StringPrototypeSlice(path, 0, startPart - 1);
1072 // Converts Windows' backslash path separators to POSIX forward slashes
1087 * path.resolve([from ...], to)
1096 const path = i >= 0 ? args[i] : posixCwd();
1097 validateString(path, `paths[${i}]`);
1100 if (path.length === 0) {
1104 resolvedPath = `${path}/${resolvedPath}`;
1106 StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;
1109 // At this point the path should be resolved to a full absolute path, but
1112 // Normalize the path
1123 * @param {string} path
1126 normalize(path) {
1127 validateString(path, 'path');
1129 if (path.length === 0)
1133 StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;
1135 StringPrototypeCharCodeAt(path, path.length - 1) === CHAR_FORWARD_SLASH;
1137 // Normalize the path
1138 path = normalizeString(path, !isAbsolute, '/', isPosixPathSeparator);
1140 if (path.length === 0) {
1146 path += '/';
1148 return isAbsolute ? `/${path}` : path;
1152 * @param {string} path
1155 isAbsolute(path) {
1156 validateString(path, 'path');
1157 return path.length > 0 &&
1158 StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;
1171 validateString(arg, 'path');
1209 // Compare paths to find the longest common path from root
1223 // We get here if `from` is the exact base path for `to`.
1235 // We get here if `to` is the exact base path for `from`.
1247 // Generate the relative path based on the path difference between `to`
1256 // Lastly, append the rest of the destination (`to`) path that comes after
1257 // the common path parts.
1262 * @param {string} path
1265 toNamespacedPath(path) {
1267 return path;
1271 * @param {string} path
1274 dirname(path) {
1275 validateString(path, 'path');
1276 if (path.length === 0)
1278 const hasRoot = StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;
1281 for (let i = path.length - 1; i >= 1; --i) {
1282 if (StringPrototypeCharCodeAt(path, i) === CHAR_FORWARD_SLASH) {
1288 // We saw the first non-path separator
1297 return StringPrototypeSlice(path, 0, end);
1301 * @param {string} path
1305 basename(path, suffix) {
1308 validateString(path, 'path');
1314 if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {
1315 if (suffix === path)
1319 for (let i = path.length - 1; i >= 0; --i) {
1320 const code = StringPrototypeCharCodeAt(path, i);
1322 // If we reached a path separator that was not part of a set of path
1330 // We saw the first non-path separator, remember this index in case
1339 // We matched the extension, so mark this as the end of our path
1344 // Extension does not match, so our result is the entire path
1356 end = path.length;
1357 return StringPrototypeSlice(path, start, end);
1359 for (let i = path.length - 1; i >= 0; --i) {
1360 if (StringPrototypeCharCodeAt(path, i) === CHAR_FORWARD_SLASH) {
1361 // If we reached a path separator that was not part of a set of path
1368 // We saw the first non-path separator, mark this as the end of our
1369 // path component
1377 return StringPrototypeSlice(path, start, end);
1381 * @param {string} path
1384 extname(path) {
1385 validateString(path, 'path');
1391 // after any path separator we find
1393 for (let i = path.length - 1; i >= 0; --i) {
1394 const code = StringPrototypeCharCodeAt(path, i);
1396 // If we reached a path separator that was not part of a set of path
1405 // We saw the first non-path separator, mark this as the end of our
1417 // We saw a non-dot and non-path separator before our dot, so we should
1427 // The (right-most) trimmed path component is exactly '..'
1433 return StringPrototypeSlice(path, startDot, end);
1439 * @param {string} path
1448 parse(path) {
1449 validateString(path, 'path');
1452 if (path.length === 0)
1455 StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;
1467 let i = path.length - 1;
1470 // after any path separator we find
1475 const code = StringPrototypeCharCodeAt(path, i);
1477 // If we reached a path separator that was not part of a set of path
1486 // We saw the first non-path separator, mark this as the end of our
1498 // We saw a non-dot and non-path separator before our dot, so we should
1509 // The (right-most) trimmed path component is exactly '..'
1513 ret.base = ret.name = StringPrototypeSlice(path, start, end);
1515 ret.name = StringPrototypeSlice(path, start, startDot);
1516 ret.base = StringPrototypeSlice(path, start, end);
1517 ret.ext = StringPrototypeSlice(path, startDot, end);
1522 ret.dir = StringPrototypeSlice(path, 0, startPart - 1);