(from: Path, to: Path)
| 127 | * Both paths must be absolute, otherwise it does not make much sense. |
| 128 | */ |
| 129 | export function relative(from: Path, to: Path): Path { |
| 130 | if (!isAbsolute(from)) { |
| 131 | throw new PathMustBeAbsoluteException(from); |
| 132 | } |
| 133 | if (!isAbsolute(to)) { |
| 134 | throw new PathMustBeAbsoluteException(to); |
| 135 | } |
| 136 | |
| 137 | let p: string; |
| 138 | |
| 139 | if (from == to) { |
| 140 | p = ''; |
| 141 | } else { |
| 142 | const splitFrom = split(from); |
| 143 | const splitTo = split(to); |
| 144 | |
| 145 | while (splitFrom.length > 0 && splitTo.length > 0 && splitFrom[0] == splitTo[0]) { |
| 146 | splitFrom.shift(); |
| 147 | splitTo.shift(); |
| 148 | } |
| 149 | |
| 150 | if (splitFrom.length == 0) { |
| 151 | p = splitTo.join(NormalizedSep); |
| 152 | } else { |
| 153 | p = splitFrom |
| 154 | .map(() => '..') |
| 155 | .concat(splitTo) |
| 156 | .join(NormalizedSep); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | return normalize(p); |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Returns a Path that is the resolution of p2, from p1. If p2 is absolute, it will return p2, |
no test coverage detected