Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/tosu/src/utils/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,17 @@ export const numberFromDecimal = (
* @returns {string} The safely joined path.
*/
export const safeJoin = (...paths: string[]): string => {
// UNC (\\server\share) paths only exist on Windows, so only preserve
// the leading double slash/backslash when running on win32.
const isUnc =
process.platform === 'win32' && /^[/\\]{2}/.test(paths[0] || '');

const cleaned = paths.map((path) => {
if (!path) return '';
return path.trim().replace(/[/\\]+/g, sep);
});

return normalize(join(...cleaned));
const result = normalize(join(...cleaned));

return isUnc ? sep + result : result;
};
Loading