(filename, outputPath, enforceRelative)
| 458 | * @returns {string} repeated ../ to leave the directory of the provided filename to be back on output dir |
| 459 | */ |
| 460 | const getUndoPath = (filename, outputPath, enforceRelative) => { |
| 461 | let depth = -1; |
| 462 | let append = ""; |
| 463 | outputPath = outputPath.replace(/[\\/]$/, ""); |
| 464 | for (const part of filename.split(/[/\\]+/)) { |
| 465 | if (part === "..") { |
| 466 | if (depth > -1) { |
| 467 | depth--; |
| 468 | } else { |
| 469 | const i = outputPath.lastIndexOf("/"); |
| 470 | const j = outputPath.lastIndexOf("\\"); |
| 471 | const pos = i < 0 ? j : j < 0 ? i : Math.max(i, j); |
| 472 | if (pos < 0) return `${outputPath}/`; |
| 473 | append = `${outputPath.slice(pos + 1)}/${append}`; |
| 474 | outputPath = outputPath.slice(0, pos); |
| 475 | } |
| 476 | } else if (part !== ".") { |
| 477 | depth++; |
| 478 | } |
| 479 | } |
| 480 | return depth > 0 |
| 481 | ? `${"../".repeat(depth)}${append}` |
| 482 | : enforceRelative |
| 483 | ? `./${append}` |
| 484 | : append; |
| 485 | }; |
| 486 | |
| 487 | const HASH_REGEXP = /(?<!\0)#/g; |
| 488 |
no test coverage detected