blob: e36d293a3343ba4e1782a16f6d58ce8c5253c5bc [file] [edit]
import { fileURLToPath } from 'node:url';
/**
* Converts a URL to a file path string, or returns the string as-is.
*
* @overload
* @param {string | URL} cwd
* @returns {string}
*
* @overload
* @param {undefined} cwd
* @returns {undefined}
*
* @overload
* @param {string | URL | undefined} cwd
* @returns {string | undefined}
*
* @param {string | URL | undefined} cwd
* @returns {string | undefined}
*/
export default function toPath(cwd) {
return cwd instanceof URL ? fileURLToPath(cwd) : cwd;
}