UNPKG

288 BJavaScriptView Raw
1import {fileURLToPath} from 'node:url';
2
3const toPath = urlOrPath => {
4 if (!urlOrPath) {
5 return urlOrPath;
6 }
7
8 if (urlOrPath instanceof URL) {
9 urlOrPath = urlOrPath.href;
10 }
11
12 return urlOrPath.startsWith('file://') ? fileURLToPath(urlOrPath) : urlOrPath;
13};
14
15export default toPath;