printTree.js 647 B

12345678910111213141516171819
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.printTree = void 0;
  4. const printTree = (tab = '', children) => {
  5. children = children.filter(Boolean);
  6. let str = '';
  7. for (let i = 0; i < children.length; i++) {
  8. const isLast = i >= children.length - 1;
  9. const fn = children[i];
  10. if (!fn)
  11. continue;
  12. const child = fn(tab + `${isLast ? ' ' : '│'} `);
  13. const branch = child ? (isLast ? '└─' : '├─') : '│ ';
  14. str += `\n${tab}${branch} ${child}`;
  15. }
  16. return str;
  17. };
  18. exports.printTree = printTree;
  19. //# sourceMappingURL=printTree.js.map