(base, target)
| 25 | }; |
| 26 | |
| 27 | export const joinRel = (base, target) => { |
| 28 | if (target.includes('://') || target.startsWith('/')) return target; |
| 29 | if (base.includes('://')) return new URL(target, base).toString(); |
| 30 | let b = base, t = target; |
| 31 | while (t.startsWith('../')) { |
| 32 | const p = parentDir(b); b = p == null ? '' : p; |
| 33 | t = t.slice(3); |
| 34 | } |
| 35 | if (t === '..') { const p = parentDir(b); return p == null ? '' : p; } |
| 36 | if (t === '.' || t === '') return b; |
| 37 | if (b !== '') { |
| 38 | while (t.startsWith('./')) t = t.slice(2); |
| 39 | if (!b.endsWith('/')) b += '/'; |
| 40 | } |
| 41 | return b + t; |
| 42 | }; |
no test coverage detected