* Gets path for path2 relative to path1 * @param {String} path1 * @param {String} path2
(path1, path2)
| 163 | * @param {String} path2 |
| 164 | */ |
| 165 | convertToRelative(path1, path2) { |
| 166 | path1 = this.normalize(path1).split("/"); |
| 167 | path2 = this.normalize(path2).split("/"); |
| 168 | |
| 169 | const p1len = path1.length; |
| 170 | const p2len = path2.length; |
| 171 | |
| 172 | let flag = false; |
| 173 | let path = []; |
| 174 | |
| 175 | path1.forEach((dir, i) => { |
| 176 | if (dir === path2[i] && !flag) return; |
| 177 | |
| 178 | path.push(path2[i]); |
| 179 | if (!flag) { |
| 180 | flag = true; |
| 181 | return; |
| 182 | } |
| 183 | |
| 184 | if (flag) path.unshift(".."); |
| 185 | }); |
| 186 | |
| 187 | if (p2len > p1len) path.push(...path2.slice(p1len)); |
| 188 | |
| 189 | return path.join("/"); |
| 190 | }, |
| 191 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected