| 16446 | // Adapted from: https://github.com/notatestuser/treeify.js |
| 16447 | _toOutline(particleFn) { |
| 16448 | const growBranch = (outlineParticle, last, lastStates, particleFn, callback) => { |
| 16449 | let lastStatesCopy = lastStates.slice(0) |
| 16450 | const particle = outlineParticle.particle |
| 16451 | if (lastStatesCopy.push([outlineParticle, last]) && lastStates.length > 0) { |
| 16452 | let line = "" |
| 16453 | // cued on the "was last element" states of whatever we're nested within, |
| 16454 | // we need to append either blankness or a branch to our line |
| 16455 | lastStates.forEach((lastState, idx) => { |
| 16456 | if (idx > 0) line += lastState[1] ? " " : "│" |
| 16457 | }) |
| 16458 | // the prefix varies cued on whether the key contains something to show and |
| 16459 | // whether we're dealing with the last element in this collection |
| 16460 | // the extra "-" just makes things stand out more. |
| 16461 | line += (last ? "└" : "├") + particleFn(particle) |
| 16462 | callback(line) |
| 16463 | } |
| 16464 | if (!particle) return |
| 16465 | const length = particle.length |
| 16466 | let index = 0 |
| 16467 | particle.forEach(particle => { |
| 16468 | let lastKey = ++index === length |
| 16469 | growBranch({ particle: particle }, lastKey, lastStatesCopy, particleFn, callback) |
| 16470 | }) |
| 16471 | } |
| 16472 | let output = "" |
| 16473 | growBranch({ particle: this }, false, [], particleFn, line => (output += line + "\n")) |
| 16474 | return output |