* It will solve the relative path from `from` to `to`, for instance * from = 'C:\\orandea\\test\\aaa' * to = 'C:\\orandea\\impl\\bbb' * The output of the function should be: '..\\..\\impl\\bbb' * @param {string} from * @param {string} to * @returns {string}
(from, to)
| 608 | * @returns {string} |
| 609 | */ |
| 610 | relative(from, to) { |
| 611 | validateString(from, 'from'); |
| 612 | validateString(to, 'to'); |
| 613 | |
| 614 | if (from === to) |
| 615 | return ''; |
| 616 | |
| 617 | const fromOrig = win32.resolve(from); |
| 618 | const toOrig = win32.resolve(to); |
| 619 | |
| 620 | if (fromOrig === toOrig) |
| 621 | return ''; |
| 622 | |
| 623 | from = StringPrototypeToLowerCase(fromOrig); |
| 624 | to = StringPrototypeToLowerCase(toOrig); |
| 625 | |
| 626 | if (from === to) |
| 627 | return ''; |
| 628 | |
| 629 | if (fromOrig.length !== from.length || toOrig.length !== to.length) { |
| 630 | const fromSplit = StringPrototypeSplit(fromOrig, '\\'); |
| 631 | const toSplit = StringPrototypeSplit(toOrig, '\\'); |
| 632 | if (fromSplit[fromSplit.length - 1] === '') { |
| 633 | fromSplit.pop(); |
| 634 | } |
| 635 | if (toSplit[toSplit.length - 1] === '') { |
| 636 | toSplit.pop(); |
| 637 | } |
| 638 | |
| 639 | const fromLen = fromSplit.length; |
| 640 | const toLen = toSplit.length; |
| 641 | const length = fromLen < toLen ? fromLen : toLen; |
| 642 | |
| 643 | let i; |
| 644 | for (i = 0; i < length; i++) { |
| 645 | if (StringPrototypeToLowerCase(fromSplit[i]) !== StringPrototypeToLowerCase(toSplit[i])) { |
| 646 | break; |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | if (i === 0) { |
| 651 | return toOrig; |
| 652 | } else if (i === length) { |
| 653 | if (toLen > length) { |
| 654 | return ArrayPrototypeJoin(ArrayPrototypeSlice(toSplit, i), '\\'); |
| 655 | } |
| 656 | if (fromLen > length) { |
| 657 | return StringPrototypeRepeat('..\\', fromLen - 1 - i) + '..'; |
| 658 | } |
| 659 | return ''; |
| 660 | } |
| 661 | |
| 662 | return StringPrototypeRepeat('..\\', fromLen - i) + ArrayPrototypeJoin(ArrayPrototypeSlice(toSplit, i), '\\'); |
| 663 | } |
| 664 | |
| 665 | // Trim any leading backslashes |
| 666 | let fromStart = 0; |
| 667 | while (fromStart < from.length && |
no test coverage detected
searching dependent graphs…