* @param {string} from * @param {string} to
(from, to)
| 421 | * @param {string} to |
| 422 | */ |
| 423 | function get_relative_path(from, to) { |
| 424 | // Don't use node's utils here to ensure the compiler is usable in a browser environment |
| 425 | const from_parts = from.split(/[/\\]/); |
| 426 | const to_parts = to.split(/[/\\]/); |
| 427 | from_parts.pop(); // get dirname |
| 428 | while (from_parts[0] === to_parts[0]) { |
| 429 | from_parts.shift(); |
| 430 | to_parts.shift(); |
| 431 | } |
| 432 | if (from_parts.length) { |
| 433 | let i = from_parts.length; |
| 434 | while (i--) from_parts[i] = '..'; |
| 435 | } |
| 436 | return from_parts.concat(to_parts).join('/'); |
| 437 | } |
| 438 | |
| 439 | /** |
| 440 | * Like node's `basename`, but doesn't use it to ensure the compiler is usable in a browser environment |
no test coverage detected