You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.0 KiB

4 years ago
  1. /**
  2. * @typedef drawBorder~parts
  3. * @property {string} left
  4. * @property {string} right
  5. * @property {string} body
  6. * @property {string} join
  7. */
  8. /**
  9. * @param {number[]} columnSizeIndex
  10. * @param {drawBorder~parts} parts
  11. * @returns {string}
  12. */
  13. const drawBorder = (columnSizeIndex, parts) => {
  14. const columns = columnSizeIndex
  15. .map((size) => {
  16. return parts.body.repeat(size);
  17. })
  18. .join(parts.join);
  19. return parts.left + columns + parts.right + '\n';
  20. };
  21. /**
  22. * @typedef drawBorderTop~parts
  23. * @property {string} topLeft
  24. * @property {string} topRight
  25. * @property {string} topBody
  26. * @property {string} topJoin
  27. */
  28. /**
  29. * @param {number[]} columnSizeIndex
  30. * @param {drawBorderTop~parts} parts
  31. * @returns {string}
  32. */
  33. const drawBorderTop = (columnSizeIndex, parts) => {
  34. const border = drawBorder(columnSizeIndex, {
  35. body: parts.topBody,
  36. join: parts.topJoin,
  37. left: parts.topLeft,
  38. right: parts.topRight
  39. });
  40. if (border === '\n') {
  41. return '';
  42. }
  43. return border;
  44. };
  45. /**
  46. * @typedef drawBorderJoin~parts
  47. * @property {string} joinLeft
  48. * @property {string} joinRight
  49. * @property {string} joinBody
  50. * @property {string} joinJoin
  51. */
  52. /**
  53. * @param {number[]} columnSizeIndex
  54. * @param {drawBorderJoin~parts} parts
  55. * @returns {string}
  56. */
  57. const drawBorderJoin = (columnSizeIndex, parts) => {
  58. return drawBorder(columnSizeIndex, {
  59. body: parts.joinBody,
  60. join: parts.joinJoin,
  61. left: parts.joinLeft,
  62. right: parts.joinRight
  63. });
  64. };
  65. /**
  66. * @typedef drawBorderBottom~parts
  67. * @property {string} topLeft
  68. * @property {string} topRight
  69. * @property {string} topBody
  70. * @property {string} topJoin
  71. */
  72. /**
  73. * @param {number[]} columnSizeIndex
  74. * @param {drawBorderBottom~parts} parts
  75. * @returns {string}
  76. */
  77. const drawBorderBottom = (columnSizeIndex, parts) => {
  78. return drawBorder(columnSizeIndex, {
  79. body: parts.bottomBody,
  80. join: parts.bottomJoin,
  81. left: parts.bottomLeft,
  82. right: parts.bottomRight
  83. });
  84. };
  85. export {
  86. drawBorder,
  87. drawBorderBottom,
  88. drawBorderJoin,
  89. drawBorderTop
  90. };