with-banner.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // @ts-check
  2. /**
  3. * @param {string} title
  4. * @param {string[]} description
  5. * @param {Date} date
  6. * @param {string[]} content
  7. * @returns {string}
  8. */
  9. const withBanner = (title, description, date, content) => {
  10. return `########################################
  11. # ${title}
  12. # Last Updated: ${date.toISOString()}
  13. # Size: ${content.length}
  14. ${description.map(line => line ? `# ${line}` : '#').join('\n')}
  15. ########################################\n` + content.join('\n') + '\n################# END ###################\n';
  16. };
  17. /**
  18. * @param {string} title
  19. * @param {string[]} description
  20. * @param {Date} date
  21. * @param {string[]} content
  22. * @returns {string[]}
  23. */
  24. const withBannerArray = (title, description, date, content) => {
  25. return [
  26. `########################################`,
  27. `# ${title}`,
  28. `# Last Updated: ${date.toISOString()}`,
  29. `# Size: ${content.length}`,
  30. ...description.map(line => line ? `# ${line}` : '#'),
  31. `########################################`,
  32. ...content,
  33. `################# END ###################`,
  34. ''
  35. ];
  36. };
  37. module.exports.withBanner = withBanner;
  38. module.exports.withBannerArray = withBannerArray;